{"id":109,"date":"2019-09-26T11:38:36","date_gmt":"2019-09-26T03:38:36","guid":{"rendered":"https:\/\/washingpatrick.cn\/?p=109"},"modified":"2019-09-26T16:33:31","modified_gmt":"2019-09-26T08:33:31","slug":"2019-9-26-leetcode","status":"publish","type":"post","link":"https:\/\/washingpatrick.cn\/index.php\/2019\/09\/26\/2019-9-26-leetcode\/","title":{"rendered":"2019\/9\/26 \u6478\u9c7c\u7b14\u8bb0"},"content":{"rendered":"<h3><a href=\"https:\/\/leetcode.com\/problems\/day-of-the-week\/\">1185. Day of the Week<\/a><\/h3>\n<h4>\u9898\u9762:<\/h4>\n<pre><code>Given a date, return the corresponding day of the week for that date.\nThe input is given as three integers representing the day, month and year respectively.\n\nReturn the answer as one of the following values {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"}.\n\nExample 1:\nInput: day = 31, month = 8, year = 2019\nOutput: \"Saturday\"\n\nExample 2:\nInput: day = 18, month = 7, year = 1999\nOutput: \"Sunday\"\n\nExample 3:\nInput: day = 15, month = 8, year = 1993\nOutput: \"Sunday\"\n\nConstraints:\n\nThe given dates are valid dates between the years 1971 and 2100.<\/code><\/pre>\n<h4>\u601d\u8def:<\/h4>\n<p>\u7528time\u5e93\uff0c\u8ba1\u7b97\u548c\u4e00\u4e2a\u5df2\u77e5\u65e5\u671f\u7684\u65f6\u95f4\u6bd4\u5bf9\u65e5\u671f\u5dee\uff0c\u4f8b\u5982 1970\u5e741\u67081\u65e5\u662f\u5468\u4e00\uff0c\u4f5c\u4e3a\u57fa\u51c6\uff0c\u8ba1\u7b97\u7ed9\u5b9a\u65e5\u671f\u5230\u8be5\u65e5\u7684\u65e5\u671f\u5dee\uff0c\u7136\u540e\u53d6\u819c7\uff0c\u5373\u5f97\u7b54\u6848\u3002<\/p>\n<h4>coding:<\/h4>\n<p>\u67e5\u770btime\u5e93\u7528\u6cd5\uff0c\u627e\u5230\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\"> 1 import time  \n 2 import datetime  \n 3   \n 4 #\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u76f8\u5dee\u5929\u6570\uff0c\u81ea\u5b9a\u4e49\u51fd\u6570\u540d\uff0c\u548c\u4e24\u4e2a\u65e5\u671f\u7684\u53d8\u91cf\u540d\u3002  \n 5 def Caltime(date1,date2):  \n 6     #%Y-%m-%d\u4e3a\u65e5\u671f\u683c\u5f0f\uff0c\u5176\u4e2d\u7684-\u53ef\u4ee5\u7528\u5176\u4ed6\u4ee3\u66ff\u6216\u8005\u4e0d\u5199\uff0c\u4f46\u662f\u8981\u7edf\u4e00\uff0c\u540c\u7406\u540e\u9762\u7684\u65f6\u5206\u79d2\u4e5f\u4e00\u6837\uff1b\u53ef\u4ee5\u53ea\u8ba1\u7b97\u65e5\u671f\uff0c\u4e0d\u8ba1\u7b97\u65f6\u95f4\u3002  \n 7     #date1=time.strptime(date1,&quot;%Y-%m-%d %H:%M:%S&quot;)   \n 8     #date2=time.strptime(date2,&quot;%Y-%m-%d %H:%M:%S&quot;)  \n 9     date1=time.strptime(date1,&quot;%Y-%m-%d&quot;)  \n10     date2=time.strptime(date2,&quot;%Y-%m-%d&quot;)  \n11     #\u6839\u636e\u4e0a\u9762\u9700\u8981\u8ba1\u7b97\u65e5\u671f\u8fd8\u662f\u65e5\u671f\u65f6\u95f4\uff0c\u6765\u786e\u5b9a\u9700\u8981\u51e0\u4e2a\u6570\u7ec4\u6bb5\u3002\u4e0b\u68070\u8868\u793a\u5e74\uff0c\u5c0f\u68071\u8868\u793a\u6708\uff0c\u4f9d\u6b21\u7c7b\u63a8...  \n12     #date1=datetime.datetime(date1[0],date1[1],date1[2],date1[3],date1[4],date1[5])  \n13     #date2=datetime.datetime(date2[0],date2[1],date2[2],date2[3],date2[4],date2[5])  \n14     date1=datetime.datetime(date1[0],date1[1],date1[2])  \n15     date2=datetime.datetime(date2[0],date2[1],date2[2])  \n16     #\u8fd4\u56de\u4e24\u4e2a\u53d8\u91cf\u76f8\u5dee\u7684\u503c\uff0c\u5c31\u662f\u76f8\u5dee\u5929\u6570  \n17     return date2-date1<\/code><\/pre>\n<p>\u7136\u540e\u4e00\u987f\u9b54\u6539\uff0c\u5f97\u5230\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import time\nimport datetime\n\nclass Solution:\n    def Caltime(self, date1, date2):\n        date1 = time.strptime(date1, &quot;%Y-%m-%d&quot;)\n        date2 = time.strptime(date2, &quot;%Y-%m-%d&quot;)\n        date1 = datetime.datetime(date1[0], date1[1], date1[2])\n        date2 = datetime.datetime(date2[0], date2[1], date2[2])\n        return date2-date1\n\n    def dayOfTheWeek(self, day, month, year):\n        day = str(day)\n        month = str(month)\n        year = str(year)\n        ans_array = [&quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;,\n                     &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;, &quot;Sunday&quot;]\n        start = &quot;1970-01-01&quot;\n        return ans_array[(self.Caltime(start, &quot;-&quot;.join([year, month, day])).days+3) % 7]\n<\/code><\/pre>\n<h4>\u7ed3\u679c<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/washingpatrick.cn\/wp-content\/uploads\/2019\/09\/2019-09-26_11-35-50-300x94.png\" alt=\"\" \/><\/p>\n<p>\u4e0b\u5348\u6478\u9c7c\u7ee7\u7eedw<\/p>\n<hr \/>\n<h3><a href=\"https:\/\/leetcode.com\/problems\/palindrome-linked-list\/\">234. Palindrome Linked List<\/a><\/h3>\n<h4>\u9898\u9762:<\/h4>\n<pre><code>Given a singly linked list, determine if it is a palindrome.\n\nExample 1:\nInput: 1->2\nOutput: false\n\nExample 2:\nInput: 1->2->2->1\nOutput: true\n\nFollow up:\nCould you do it in O(n) time and O(1) space?<\/code><\/pre>\n<h4>\u601d\u8def:<\/h4>\n<p>\u7b80\u5355\u7684\u56de\u6587\u5224\u65ad\uff0c\u76f4\u63a5\u52a0\u5230\u4e00\u4e2alist\u518d\u548creverse\u4f5c\u6bd4\u8f83\u5c31\u884c~<br \/>\n\u65e2\u7136\u6709<code><code>Follow up<\/code><\/code>\u90a3\u5c31\u6311\u6218\u4e00\u4e0b:<\/p>\n<ul>\n<li>\u5efa\u7acb\u4e24\u4e2a\u6307\u9488\uff0c\u4e00\u4e2a\u4e3a<code><code>fast<\/code>`<code>\uff0c\u4e00\u4e2a\u4e3a<\/code>`<code>slow<\/code><\/code><\/li>\n<li><code><code>fast<\/code>`<code>\u4e00\u6b21\u79fb\u52a8\u4e24\u4e2a\u5355\u4f4d\uff0c<\/code>`<code>slow<\/code><\/code>\u4e00\u6b21\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\uff0c\u5e76\u4e14\u4f7f\u524d\u90e8\u94fe\u8868\u53cd\u8f6c<\/li>\n<li>\u5f53<code><code>fast<\/code>`<code>\u79fb\u52a8\u81f3\u672b\u5c3e\u65f6\uff0c<\/code>`<code>fast<\/code><\/code>\u6307\u5411\u5934<\/li>\n<li><code><code>fast<\/code>`<code>\u548c<\/code>`<code>slow<\/code>`<code>\u5747\u4e00\u6b21\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\uff0c\u76f4\u5230<\/code>`<code>slow<\/code>`<code>\u5230\u5934\uff0c\u6bcf\u6b21\u79fb\u52a8\u5747\u6bd4\u5bf9<\/code>`<code>fast<\/code>`<code>\u4e0e<\/code>`<code>slow<\/code><\/code>\u7684\u503c\u662f\u5426\u4e00\u81f4\uff0c\u5982\u4e0d\u4e00\u81f4\uff0c\u5219\u4e0d\u4e3a\u56de\u6587<\/li>\n<li>\u8be5\u94fe\u8868\u4e3a\u56de\u6587<\/li>\n<\/ul>\n<h4>coding:<\/h4>\n<pre><code class=\"language-python\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1185. Day of the Week \u9898\u9762: Given a date, return the corr&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/washingpatrick.cn\/index.php\/2019\/09\/26\/2019-9-26-leetcode\/\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-leetcode"],"_links":{"self":[{"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":2,"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions\/112"}],"wp:attachment":[{"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/washingpatrick.cn\/index.php\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}