{"id":3196,"date":"2023-10-21T23:32:21","date_gmt":"2023-10-21T15:32:21","guid":{"rendered":"https:\/\/white-night.club\/?p=3196"},"modified":"2023-11-09T11:07:47","modified_gmt":"2023-11-09T03:07:47","slug":"ad82","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/21\/ad82\/","title":{"rendered":"1991.\u00a0\u627e\u5230\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece\u00a0<strong>0<\/strong>\u00a0\u5f00\u59cb\u7684\u6574\u6570\u6570\u7ec4\u00a0<code>nums<\/code>\u00a0\uff0c\u8bf7\u4f60\u627e\u5230\u00a0<strong>\u6700\u5de6\u8fb9<\/strong>\u00a0\u7684\u4e2d\u95f4\u4f4d\u7f6e\u00a0<code>middleIndex<\/code>\u00a0\uff08\u4e5f\u5c31\u662f\u6240\u6709\u53ef\u80fd\u4e2d\u95f4\u4f4d\u7f6e\u4e0b\u6807\u6700\u5c0f\u7684\u4e00\u4e2a\uff09\u3002<\/p>\n\n\n\n<p>\u4e2d\u95f4\u4f4d\u7f6e&nbsp;<code>middleIndex<\/code>&nbsp;\u662f\u6ee1\u8db3&nbsp;<code>nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1]<\/code>&nbsp;\u7684\u6570\u7ec4\u4e0b\u6807\u3002<\/p>\n\n\n\n<p>\u5982\u679c&nbsp;<code>middleIndex == 0<\/code>&nbsp;\uff0c\u5de6\u8fb9\u90e8\u5206\u7684\u548c\u5b9a\u4e49\u4e3a&nbsp;<code>0<\/code>&nbsp;\u3002\u7c7b\u4f3c\u7684\uff0c\u5982\u679c&nbsp;<code>middleIndex == nums.length - 1<\/code>&nbsp;\uff0c\u53f3\u8fb9\u90e8\u5206\u7684\u548c\u5b9a\u4e49\u4e3a&nbsp;<code>0<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6&nbsp;<strong>\u6700\u5de6\u8fb9<\/strong>&nbsp;\u7684<em>&nbsp;<\/em><code>middleIndex<\/code>&nbsp;\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e2d\u95f4\u4f4d\u7f6e\uff0c\u8bf7\u4f60\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 = [2,3,-1,<em><strong>8<\/strong><\/em>,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>3\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e0b\u6807 3 \u4e4b\u524d\u7684\u6570\u5b57\u548c\u4e3a\uff1a2 + 3 + -1 = 4\n\u4e0b\u6807 3 \u4e4b\u540e\u7684\u6570\u5b57\u548c\u4e3a\uff1a4 = 4\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,-1,<em><strong>4<\/strong><\/em>]\n<strong>\u8f93\u51fa\uff1a<\/strong>2\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e0b\u6807 2 \u4e4b\u524d\u7684\u6570\u5b57\u548c\u4e3a\uff1a1 + -1 = 0\n\u4e0b\u6807 2 \u4e4b\u540e\u7684\u6570\u5b57\u548c\u4e3a\uff1a0\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 = [2,5]\n<strong>\u8f93\u51fa\uff1a<\/strong>-1\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e0d\u5b58\u5728\u7b26\u5408\u8981\u6c42\u7684 middleIndex \u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 4\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [<em><strong>1<\/strong><\/em>]\n<strong>\u8f93\u51fa\uff1a<\/strong>0\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e0b\u6807 0 \u4e4b\u524d\u7684\u6570\u5b57\u548c\u4e3a\uff1a0\n\u4e0b\u6807 0 \u4e4b\u540e\u7684\u6570\u5b57\u548c\u4e3a\uff1a0\n<\/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;= 100<\/code><\/li>\n\n\n\n<li><code>-1000 &lt;= nums[i] &lt;= 1000<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u672c\u9898\u4e0e\u4e3b\u7ad9 724 \u9898\u76f8\u540c<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0086ff\" class=\"has-inline-color\">\uff1a<\/mark><a rel=\"noreferrer noopener\" href=\"https:\/\/leetcode-cn.com\/problems\/find-pivot-index\/\" target=\"_blank\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0086ff\" class=\"has-inline-color\">https:\/\/leetcode-cn.com\/problems\/find-pivot-index\/<\/mark><\/a><\/p>\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>\u8fd9\u9898\u4e4b\u524d\u5199\u8fc7\u3002\u5fd8\u8bb0\u548b\u5199\u7684\u65f6\u5019\u5c31cout\u4e00\u4e0b\uff0c\u9a6c\u4e0a\u5c31\u60f3\u8d77\u6765\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\r\npublic:\r\n    int findMiddleIndex(vector&lt;int>&amp; nums) {\r\n        int size=nums.size();\r\n        vector&lt;int>sum;\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        int index=-1;\r\n        for(int i=0;i&lt;size;i++)\r\n        {\r\n            if(sum&#91;size]-sum&#91;i]==sum&#91;i+1])\r\n            {\r\n                return i;\r\n            }\r\n        }\r\n        return index;\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\/3196"}],"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=3196"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3196\/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=3196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}