{"id":2213,"date":"2022-01-21T15:37:01","date_gmt":"2022-01-21T07:37:01","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2213"},"modified":"2022-01-21T15:37:02","modified_gmt":"2022-01-21T07:37:02","slug":"leetcodeday53","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/21\/leetcodeday53\/","title":{"rendered":"leetcodeday53 &#8211;\u6700\u5927\u5b50\u6570\u7ec4\u548c"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u5177\u6709\u6700\u5927\u548c\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff08\u5b50\u6570\u7ec4\u6700\u5c11\u5305\u542b\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u8fd4\u56de\u5176\u6700\u5927\u548c\u3002<\/p>\n\n\n\n<p><strong>\u5b50\u6570\u7ec4&nbsp;<\/strong>\u662f\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u90e8\u5206\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [-2,1,-3,4,-1,2,1,-5,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>6\n<strong>\u89e3\u91ca\uff1a<\/strong>\u8fde\u7eed\u5b50\u6570\u7ec4&nbsp;[4,-1,2,1] \u7684\u548c\u6700\u5927\uff0c\u4e3a&nbsp;6 \u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [1]\n<strong>\u8f93\u51fa\uff1a<\/strong>1\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [5,4,-1,7,8]\n<strong>\u8f93\u51fa\uff1a<\/strong>23\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= nums.length &lt;= 10<sup>5<\/sup><\/code><\/li><li><code>-10<sup>4<\/sup>&nbsp;&lt;= nums[i] &lt;= 10<sup>4<\/sup><\/code><\/li><\/ul>\n\n\n\n<p>\u6cd5\u4e00\uff1a\u66b4\u529b\u6c42\u89e3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc code=start\nclass Solution:\n    def maxSubArray(self, nums: List&#91;int]) -&gt; int:\n        lens=len(nums) \n        maxs=nums&#91;0]\n        for i in range(lens):\n            for j in range(0,i+1):\n                maxs=max(maxs,sum(nums&#91;j:i+1]))\n        return maxs\n<\/code><\/pre>\n\n\n\n<p>\u8d85\u65f6\u4e86<\/p>\n\n\n\n<p>\u6cd5\u4e8c\uff1a\u52a8\u6001\u89c4\u5212<\/p>\n\n\n\n<p>\u6211\u4eec\u7528 <em>f<\/em>(<em>i<\/em>)&nbsp;\u4ee3\u8868\u4ee5<strong>\u7b2c&nbsp;<em>i<\/em>&nbsp;\u4e2a\u6570\u7ed3\u5c3e\u7684<\/strong>\u300c\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c\u300d\uff0c\u90a3\u4e48\u5f88\u663e\u7136\u6211\u4eec\u8981\u6c42\u7684\u7b54\u6848\u5c31\u662f\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-254.png\" alt=\"\" class=\"wp-image-2219\" width=\"212\" height=\"69\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-254.png 368w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-254-300x97.png 300w\" sizes=\"(max-width: 212px) 100vw, 212px\" \/><\/figure><\/div>\n\n\n\n<p>\u56e0\u6b64\u6211\u4eec\u53ea\u9700\u8981\u6c42\u51fa\u6bcf\u4e2a\u4f4d\u7f6e\u7684<em>f<\/em>(<em>i<\/em>)\uff0c\u7136\u540e\u8fd4\u56de&nbsp;<em>f<\/em>&nbsp;\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u5373\u53ef\u3002\u90a3\u4e48\u6211\u4eec\u5982\u4f55\u6c42&nbsp;<em>f<\/em>(<em>i<\/em>)&nbsp;\u5462\uff1f\u6211\u4eec\u53ef\u4ee5\u8003\u8651<em>nums<\/em>[<em>i<\/em>]&nbsp;\u5355\u72ec\u6210\u4e3a\u4e00\u6bb5\u8fd8\u662f\u52a0\u5165&nbsp;<em>f<\/em>(<em>i<\/em>\u22121)&nbsp;\u5bf9\u5e94\u7684\u90a3\u4e00\u6bb5\uff0c\u8fd9\u53d6\u51b3\u4e8e&nbsp;<em>nums<\/em>[<em>i<\/em>]&nbsp;\u548c&nbsp;<em>f<\/em>(<em>i<\/em>\u22121)+<em>nums<\/em>[<em>i<\/em>]&nbsp;\u7684\u5927\u5c0f\uff0c\u6211\u4eec\u5e0c\u671b\u83b7\u5f97\u4e00\u4e2a\u6bd4\u8f83\u5927\u7684\uff0c\u4e8e\u662f\u53ef\u4ee5\u5199\u51fa\u8fd9\u6837\u7684\u52a8\u6001\u89c4\u5212\u8f6c\u79fb\u65b9\u7a0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-255.png\" alt=\"\" class=\"wp-image-2220\" width=\"459\" height=\"51\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-255.png 679w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-255-300x34.png 300w\" sizes=\"(max-width: 459px) 100vw, 459px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def maxSubArray(self, nums: List&#91;int]) -&gt; int:\n        lens=len(nums)\n        maxs=nums&#91;0]\n        n=0\n        for i in range(lens):\n            n=max(n+nums&#91;i],nums&#91;i])\n            maxs=max(maxs,n)\n        return maxs<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-256.png\" alt=\"\" class=\"wp-image-2222\" width=\"496\" height=\"168\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-256.png 741w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-256-300x102.png 300w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;nums&nbsp;\uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u5177\u6709\u6700\u5927\u548c\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff08\u5b50\u6570\u7ec4\u6700\u5c11\u5305\u542b\u4e00\u4e2a\u5143\u7d20\uff09 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/21\/leetcodeday53\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday53 &#8211;\u6700\u5927\u5b50\u6570\u7ec4\u548c<\/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\/2213"}],"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=2213"}],"version-history":[{"count":7,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2213\/revisions"}],"predecessor-version":[{"id":2223,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2213\/revisions\/2223"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2213"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}