{"id":2598,"date":"2022-02-04T13:21:55","date_gmt":"2022-02-04T05:21:55","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2598"},"modified":"2022-02-04T13:21:56","modified_gmt":"2022-02-04T05:21:56","slug":"leetcodeday123","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday123\/","title":{"rendered":"leetcodeday123&#8211; \u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III\uff08!\uff09"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5b83\u7684\u7b2c<code>i<\/code>&nbsp;\u4e2a\u5143\u7d20\u662f\u4e00\u652f\u7ed9\u5b9a\u7684\u80a1\u7968\u5728\u7b2c&nbsp;<code>i<\/code>\u5929\u7684\u4ef7\u683c\u3002<\/p>\n\n\n\n<p>\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u5b8c\u6210&nbsp;<strong>\u4e24\u7b14&nbsp;<\/strong>\u4ea4\u6613\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"1019\" height=\"942\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-33.png\" alt=\"\" class=\"wp-image-2600\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-33.png 1019w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-33-300x277.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-33-768x710.png 768w\" sizes=\"(max-width: 1019px) 100vw, 1019px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"584\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-34-1024x584.png\" alt=\"\" class=\"wp-image-2601\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-34-1024x584.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-34-300x171.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-34-768x438.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-34.png 1116w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=123 lang=python3\r\n#\r\n# &#91;123] \u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n\r\n    def maxProfit(self, prices: List&#91;int]) -> int:\r\n        n = len(prices)\r\n        buy1 = buy2 = -prices&#91;0]\r\n        sell1 = sell2 = 0\r\n        for i in range(1, n):\r\n            buy1 = max(buy1, -prices&#91;i])\r\n            sell1 = max(sell1, buy1 + prices&#91;i])\r\n            buy2 = max(buy2, sell1 - prices&#91;i])\r\n            sell2 = max(sell2, buy2 + prices&#91;i])\r\n        return sell2\r\n# @lc code=end\r\n\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"789\" height=\"206\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-32.png\" alt=\"\" class=\"wp-image-2599\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-32.png 789w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-32-300x78.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-32-768x201.png 768w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5b83\u7684\u7b2ci&nbsp;\u4e2a\u5143\u7d20\u662f\u4e00\u652f\u7ed9\u5b9a\u7684\u80a1\u7968\u5728\u7b2c&nbsp;i\u5929\u7684\u4ef7\u683c\u3002 \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday123\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday123&#8211; \u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III\uff08!\uff09<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2598"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2598"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2598\/revisions"}],"predecessor-version":[{"id":2602,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2598\/revisions\/2602"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2598"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}