1154. Day of the Year
https://leetcode.com/problems/day-of-the-year/
Given a string date
representing a Gregorian calendar date formatted as YYYY-MM-DD
, return the day number of the year.
Example 1:
Example 2:
Example 3:
Example 4:
给一个以xxxx-xx-xx为格式的日期,问是那年的第几天。把每个月的天数列出来,然后遍历到指定月的前一个月加起来。判断月是不是>2且年是不是闰年,是就天数再加1。
代码参考自这。
Last updated
Was this helpful?