{"id":3571,"date":"2023-10-27T11:12:49","date_gmt":"2023-10-27T03:12:49","guid":{"rendered":"https:\/\/white-night.club\/?p=3571"},"modified":"2023-11-09T11:07:45","modified_gmt":"2023-11-09T03:07:45","slug":"ad104","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/27\/ad104\/","title":{"rendered":"LCR 012.\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<p>\u6ce8\u610f\uff1a\u672c\u9898\u4e0e\u4e3b\u7ad9 724\u00a0\u9898\u76f8\u540c\uff1a<mark style=\"background-color:rgba(0, 0, 0, 0);color:#0086ff\" class=\"has-inline-color\">\u00a0<\/mark><a href=\"https:\/\/leetcode-cn.com\/problems\/find-pivot-index\/\" target=\"_blank\" rel=\"noreferrer noopener\"><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>\u8fd8\u5269\u4e24\u9053\u524d\u7f00\u548c\u7684\u7b80\u5355\u9898\uff0c\u53e6\u4e00\u9053\u8c8c\u4f3c\u8981\u7528\u8d2a\u5fc3\u6c42\u5c40\u90e8\u6700\u4f18\u89e3\uff0c\u4f46\u6211\u73b0\u5728\u8d2a\u5fc3\u7528\u7684\u8fd8\u4e0d\u719f\uff0c\u6240\u4ee5\u5148\u4e0d\u5199\u90a3\u9053\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u9053\u4e4b\u524d\u5199\u8fc7\u4e86\uff0c\u521a\u597d\u6700\u8fd1\u5728\u5b66go\uff0c\u6240\u4ee5\u5c31\u7528go\u91cd\u65b0\u5199\u4e86\u4e00\u4e0b\uff0c\u601d\u8def\u8fd8\u662f\u4e00\u6837\u7684\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7\u6709\u90a3\u4e48\u4e00\u77ac\u95f4\u5728\u60f3return i\u90a3\u5757\u7684sum[i+1]\u4f1a\u4e0d\u4f1a\u6ea2\u51fa\uff0c\u4f46\u60f3\u4e86\u4e0bi+1\u6700\u5927\u5c31\u662fn\uff0c\u4e5f\u5c31\u662fsum[n]\uff0c\u6240\u4ee5\u8fd8\u662f\u4e0d\u4f1a\u6ea2\u51fa\u7684\u3002\u53ea\u80fd\u8bf4\u8fd9\u91cc\u8fd8\u6ca1\u5b8c\u5168\u638c\u63e1\u624d\u4f1a\u6000\u7591\u3002<\/p>\n\n\n\n<p>\u800c\u4e14\u5fc5\u987b\u8981\u5199return,\u56e0\u4e3a\u8fd4\u56de\u7684\u662f\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4e2d\u5fc3\u4e0b\u6807\u3002\u7b49\u641e\u5b8c\u8d2a\u5fc3\u518d\u5199\u53e6\u4e00\u9053\u524d\u7f00\u548c+\u8d2a\u5fc3\u7684\u9898\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func pivotIndex(nums &#91;]int) int {\r\n    n:=len(nums)\r\n    sum:=make(&#91;]int,n+1)\r\n    index:=-1\r\n    for i:=0;i&lt;n;i++{\r\n        sum&#91;i+1]=sum&#91;i]+nums&#91;i]\r\n    }\r\n    for i:=0;i&lt;n;i++{\r\n        if sum&#91;n]-sum&#91;i]==sum&#91;i+1]{\r\n            return i\r\n        }\r\n    }\r\n    return index\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\/3571"}],"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=3571"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3571\/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=3571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}