<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>leap year Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/leap-year/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/leap-year/</link>
	<description></description>
	<lastBuildDate>Sun, 08 Sep 2019 04:18:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>leap year Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/leap-year/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1185. Day of the Week</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-1185-day-of-the-week/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-1185-day-of-the-week/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 08 Sep 2019 04:18:17 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[leap year]]></category>
		<category><![CDATA[math]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5531</guid>

					<description><![CDATA[<p>Given a date, return the corresponding day of the week for that date. The input is given as three integers representing the&#160;day,&#160;month&#160;and&#160;year&#160;respectively. Return the answer&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1185-day-of-the-week/">花花酱 LeetCode 1185. Day of the Week</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given a date, return the corresponding day of the week for that date.</p>



<p>The input is given as three integers representing the&nbsp;<code>day</code>,&nbsp;<code>month</code>&nbsp;and&nbsp;<code>year</code>&nbsp;respectively.</p>



<p>Return the answer as one of the following values&nbsp;<code>{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}</code>.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> day = 31, month = 8, year = 2019
<strong>Output:</strong> "Saturday"
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> day = 18, month = 7, year = 1999
<strong>Output:</strong> "Sunday"
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> day = 15, month = 8, year = 1993
<strong>Output:</strong> "Sunday"
</pre>



<p><strong>Constraints:</strong></p>



<ul><li>The given dates are valid&nbsp;dates between the years&nbsp;<code>1971</code>&nbsp;and&nbsp;<code>2100</code>.</li></ul>



<p><strong>Solution: LeapYear</strong></p>



<p>Time complexity: O(1)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
inline bool leapYear(int y) {
  return (y % 4 == 0 &amp;&amp; y % 100 != 0) || (y % 400 == 0);
}
class Solution {
public:
  string dayOfTheWeek(int day, int month, int year) {    
    vector&lt;string&gt; names = {&quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;};
    vector&lt;int&gt; days = {31, 28 + leapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int sum = 0;
    for (int i = 1970; i &lt; year; ++i)
      sum += 365 + leapYear(i);    
    for (int i = 1; i &lt; month; ++i)
      sum += days[i - 1];    
    sum += day;
    return names[(sum + 3) % 7];
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1185-day-of-the-week/">花花酱 LeetCode 1185. Day of the Week</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/math/leetcode-1185-day-of-the-week/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 1154. Day of the Year</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-1154-day-of-the-year/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-1154-day-of-the-year/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 11 Aug 2019 19:32:33 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[leap year]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5418</guid>

					<description><![CDATA[<p>Given a string&#160;date&#160;representing a&#160;Gregorian&#160;calendar&#160;date formatted as&#160;YYYY-MM-DD, return the day number of the year. Example 1: Input: date = "2019-01-09" Output: 9 Explanation: Given date is&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1154-day-of-the-year/">花花酱 LeetCode 1154. Day of the Year</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given a string&nbsp;<code>date</code>&nbsp;representing a&nbsp;<a href="https://en.wikipedia.org/wiki/Gregorian_calendar" target="_blank" rel="noreferrer noopener">Gregorian&nbsp;calendar</a>&nbsp;date formatted as&nbsp;<code>YYYY-MM-DD</code>, return the day number of the year.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><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 class="wp-block-preformatted;crayon:false"><strong>Input:</strong> date = "2019-02-10"
<strong>Output:</strong> 41
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> date = "2003-03-01"
<strong>Output:</strong> 60
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> date = "2004-03-01"
<strong>Output:</strong> 61
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>date.length == 10</code></li><li><code>date[4] == date[7] == '-'</code>, and all other&nbsp;<code>date[i]</code>&#8216;s are digits</li><li><code>date</code>&nbsp;represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.</li></ul>



<h2><strong>Solution: </strong></h2>



<p>Key: checking whether that year is a leap year or not.<br>is_leap = (year % 4 == 0 and year % 100 !=0) or year % 400 == 0</p>



<p>Time complexity: O(1)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">Python</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag"># Author: Huahua
class Solution:
  def dayOfYear(self, date: str) -&gt; int:
    y, m, d = int(date.split(&quot;-&quot;)[0]), int(date.split(&quot;-&quot;)[1]), int(date.split(&quot;-&quot;)[2])
    leap = (y % 4 == 0 and y % 100 != 0) or y % 400 == 0
    days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    s = sum(days[0:m-1]) + d
    if leap and m &gt; 2: s += 1
    return s</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1154-day-of-the-year/">花花酱 LeetCode 1154. Day of the Year</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/string/leetcode-1154-day-of-the-year/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
