{"id":2605,"date":"2023-10-15T12:45:37","date_gmt":"2023-10-15T04:45:37","guid":{"rendered":"https:\/\/white-night.club\/?p=2605"},"modified":"2023-11-09T11:07:49","modified_gmt":"2023-11-09T03:07:49","slug":"ad56","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/15\/ad56\/","title":{"rendered":"724.\u00a0\u5bfb\u627e\u6570\u7ec4\u7684\u4e2d\u5fc3\u4e0b\u6807"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0<code>nums<\/code>\u00a0\uff0c\u8bf7\u8ba1\u7b97\u6570\u7ec4\u7684\u00a0<strong>\u4e2d\u5fc3\u4e0b\u6807\u00a0<\/strong>\u3002<\/p>\n\n\n\n<p>\u6570\u7ec4<strong>&nbsp;\u4e2d\u5fc3\u4e0b\u6807<\/strong><strong>&nbsp;<\/strong>\u662f\u6570\u7ec4\u7684\u4e00\u4e2a\u4e0b\u6807\uff0c\u5176\u5de6\u4fa7\u6240\u6709\u5143\u7d20\u76f8\u52a0\u7684\u548c\u7b49\u4e8e\u53f3\u4fa7\u6240\u6709\u5143\u7d20\u76f8\u52a0\u7684\u548c\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4e2d\u5fc3\u4e0b\u6807\u4f4d\u4e8e\u6570\u7ec4\u6700\u5de6\u7aef\uff0c\u90a3\u4e48\u5de6\u4fa7\u6570\u4e4b\u548c\u89c6\u4e3a&nbsp;<code>0<\/code>&nbsp;\uff0c\u56e0\u4e3a\u5728\u4e0b\u6807\u7684\u5de6\u4fa7\u4e0d\u5b58\u5728\u5143\u7d20\u3002\u8fd9\u4e00\u70b9\u5bf9\u4e8e\u4e2d\u5fc3\u4e0b\u6807\u4f4d\u4e8e\u6570\u7ec4\u6700\u53f3\u7aef\u540c\u6837\u9002\u7528\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6570\u7ec4\u6709\u591a\u4e2a\u4e2d\u5fc3\u4e0b\u6807\uff0c\u5e94\u8be5\u8fd4\u56de&nbsp;<strong>\u6700\u9760\u8fd1\u5de6\u8fb9<\/strong>&nbsp;\u7684\u90a3\u4e00\u4e2a\u3002\u5982\u679c\u6570\u7ec4\u4e0d\u5b58\u5728\u4e2d\u5fc3\u4e0b\u6807\uff0c\u8fd4\u56de&nbsp;<code>-1<\/code>&nbsp;\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 = [1, 7, 3, 6, 5, 6]\n<strong>\u8f93\u51fa\uff1a<\/strong>3\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e2d\u5fc3\u4e0b\u6807\u662f 3 \u3002\n\u5de6\u4fa7\u6570\u4e4b\u548c sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11 \uff0c\n\u53f3\u4fa7\u6570\u4e4b\u548c sum = nums[4] + nums[5] = 5 + 6 = 11 \uff0c\u4e8c\u8005\u76f8\u7b49\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, 2, 3]\n<strong>\u8f93\u51fa\uff1a<\/strong>-1\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u4e2d\u5fc3\u4e0b\u6807\u3002<\/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 = [2, 1, -1]\n<strong>\u8f93\u51fa\uff1a<\/strong>0\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e2d\u5fc3\u4e0b\u6807\u662f 0 \u3002\n\u5de6\u4fa7\u6570\u4e4b\u548c sum = 0 \uff0c\uff08\u4e0b\u6807 0 \u5de6\u4fa7\u4e0d\u5b58\u5728\u5143\u7d20\uff09\uff0c\n\u53f3\u4fa7\u6570\u4e4b\u548c sum = nums[1] + nums[2] = 1 + -1 = 0 \u3002<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>1 &lt;= nums.length &lt;= 10<sup>4<\/sup><\/code><\/li>\n\n\n\n<li><code>-1000 &lt;= nums[i] &lt;= 1000<\/code><\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u524d\u7f00\u548c<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6c42\u6570\u7ec4\u67d0\u4e2a\u533a\u95f4\u5185\u7684\u548c\uff0c\u90a3\u5c31\u80af\u5b9a\u662f\u7528\u524d\u7f00\u548c\u4e86\u3002\u90a3\u4e48\u5148\u628a\u524d\u7f00\u548c\u8ba1\u7b97\u51fa\u6765\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\npublic:\n    int pivotIndex(vector&lt;int>&amp; nums) {\n        vector&lt;int>sum;\n        int size=nums.size();\n        sum.resize(size+1);\n        for(int i=0;i&lt;size;i++)\n            sum&#91;i+1]=sum&#91;i]+nums&#91;i];\n      <mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/\/TODO\uff1a\u8ba1\u7b97\u4e2d\u5fc3\u4e0b\u6807<\/mark>\n\n    }\n};<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u770b\u770b\u4e2d\u5fc3\u4e0b\u6807\u3002\u5de6\u90e8\u6bd4\u8f83\u597d\u5904\u7406\uff0c\u76f4\u63a5\u5c31\u662f\u6570\u7ec4\u524dn\u9879\u548c\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u5047\u8bbe\u8981\u6c42\u7684\u4e0b\u6807\u4e3ax\u3002\u90a3\u4e48\u6211\u4eec\u5b9e\u9645\u4e0a\u8981\u5224\u65ad\u7684\u662f\u4ec0\u4e48\u65f6\u5019\u4f1a\u6709<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>a0+a1+&#8230;+a<sub>x-1<\/sub>=a<sub>x+1<\/sub>+&#8230;+an<\/em><\/strong><\/p>\n\n\n\n<p>\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684x\u5c31\u662f\u6211\u4eec\u8981\u627e\u7684\u4e2d\u5fc3\u4e0b\u6807\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\r\npublic:\r\n    int pivotIndex(vector&lt;int>&amp; nums) {\r\n        vector&lt;int>sum;\r\n        int size=nums.size();\r\n        sum.resize(size+1);\r\n        for(int i=0;i&lt;size;i++)\r\n            sum&#91;i+1]=sum&#91;i]+nums&#91;i];\r\n                                   \r\n        for(int index=0;index&lt;size;index++)\r\n            if(sum&#91;size]-sum&#91;index]==sum&#91;index+1])\r\n                return index;\r\n        return -1;\r\n    }\r\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u524d\u7f00\u548c<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2605"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2605"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2605\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}