{"id":2587,"date":"2022-02-04T12:57:24","date_gmt":"2022-02-04T04:57:24","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2587"},"modified":"2022-02-04T12:57:26","modified_gmt":"2022-02-04T04:57:26","slug":"leetcodeday121","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday121\/","title":{"rendered":"leetcodeday121&#8211;\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4&nbsp;<code>prices<\/code>&nbsp;\uff0c\u5b83\u7684\u7b2c&nbsp;<code>i<\/code>&nbsp;\u4e2a\u5143\u7d20&nbsp;<code>prices[i]<\/code>&nbsp;\u8868\u793a\u4e00\u652f\u7ed9\u5b9a\u80a1\u7968\u7b2c&nbsp;<code>i<\/code>&nbsp;\u5929\u7684\u4ef7\u683c\u3002<\/p>\n\n\n\n<p>\u4f60\u53ea\u80fd\u9009\u62e9&nbsp;<strong>\u67d0\u4e00\u5929<\/strong>&nbsp;\u4e70\u5165\u8fd9\u53ea\u80a1\u7968\uff0c\u5e76\u9009\u62e9\u5728&nbsp;<strong>\u672a\u6765\u7684\u67d0\u4e00\u4e2a\u4e0d\u540c\u7684\u65e5\u5b50<\/strong>&nbsp;\u5356\u51fa\u8be5\u80a1\u7968\u3002\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u4f60\u53ef\u4ee5\u4ece\u8fd9\u7b14\u4ea4\u6613\u4e2d\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u5982\u679c\u4f60\u4e0d\u80fd\u83b7\u53d6\u4efb\u4f55\u5229\u6da6\uff0c\u8fd4\u56de&nbsp;<code>0<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>&#91;7,1,5,3,6,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>5\n<strong>\u89e3\u91ca\uff1a<\/strong>\u5728\u7b2c 2 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 6\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u6700\u5927\u5229\u6da6 = 6-1 = 5 \u3002\n     \u6ce8\u610f\u5229\u6da6\u4e0d\u80fd\u662f 7-1 = 6, \u56e0\u4e3a\u5356\u51fa\u4ef7\u683c\u9700\u8981\u5927\u4e8e\u4e70\u5165\u4ef7\u683c\uff1b\u540c\u65f6\uff0c\u4f60\u4e0d\u80fd\u5728\u4e70\u5165\u524d\u5356\u51fa\u80a1\u7968\u3002<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=121 lang=python3\r\n#\r\n# &#91;121] \u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a\r\n# \r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def maxProfit(self, prices: List&#91;int]) -> int:\r\n        minprice=prices&#91;0]\r\n        maxprice=0\r\n        for i in range(1,len(prices)):\r\n            maxprice=max(maxprice, prices&#91;i]-minprice)\r\n            minprice=min(minprice,prices&#91;i])\r\n        return maxprice\r\n# @lc code=end\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"883\" height=\"230\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-28.png\" alt=\"\" class=\"wp-image-2588\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-28.png 883w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-28-300x78.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-28-768x200.png 768w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4&nbsp;prices&nbsp;\uff0c\u5b83\u7684\u7b2c&nbsp;i&nbsp;\u4e2a\u5143\u7d20&nbsp;price &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday121\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday121&#8211;\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a<\/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\/2587"}],"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=2587"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2587\/revisions"}],"predecessor-version":[{"id":2590,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2587\/revisions\/2590"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2587"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}