-
Notifications
You must be signed in to change notification settings - Fork 160
/
day-of-the-year.md
40 lines (30 loc) · 1.17 KB
/
day-of-the-year.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<p>Given a string <code>date</code> representing a <a href="https://en.wikipedia.org/wiki/Gregorian_calendar" target="_blank">Gregorian calendar</a> date formatted as <code>YYYY-MM-DD</code>, return the day number of the year.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> date = "2019-01-09"
<strong>Output:</strong> 9
<strong>Explanation:</strong> Given date is the 9th day of the year in 2019.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> date = "2019-02-10"
<strong>Output:</strong> 41
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> date = "2003-03-01"
<strong>Output:</strong> 60
</pre>
<p><strong>Example 4:</strong></p>
<pre>
<strong>Input:</strong> date = "2004-03-01"
<strong>Output:</strong> 61
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>date.length == 10</code></li>
<li><code>date[4] == date[7] == '-'</code>, and all other <code>date[i]</code>'s are digits</li>
<li><code>date</code> represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.</li>
</ul>