{"id":5489,"date":"2023-11-22T19:43:39","date_gmt":"2023-11-22T11:43:39","guid":{"rendered":"https:\/\/white-night.club\/?p=5489"},"modified":"2023-11-22T19:45:02","modified_gmt":"2023-11-22T11:45:02","slug":"ad162","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/22\/ad162\/","title":{"rendered":"1.\u00a0\u4e24\u6570\u4e4b\u548c"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0<code>nums<\/code>\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c\u00a0<code>target<\/code>\uff0c\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u00a0<strong>\u548c\u4e3a\u76ee\u6807\u503c\u00a0<\/strong><em><code>target<\/code><\/em>\u00a0 \u7684\u90a3\u00a0<strong>\u4e24\u4e2a<\/strong>\u00a0\u6574\u6570\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848\u3002\u4f46\u662f\uff0c\u6570\u7ec4\u4e2d\u540c\u4e00\u4e2a\u5143\u7d20\u5728\u7b54\u6848\u91cc\u4e0d\u80fd\u91cd\u590d\u51fa\u73b0\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><strong>\u8f93\u5165\uff1a<\/strong>nums = [2,7,11,15], target = 9 <strong>\u8f93\u51fa\uff1a<\/strong>[0,1] <strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a nums[0] + nums[1] == 9 \uff0c\u8fd4\u56de [0, 1] \u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><strong>\u8f93\u5165\uff1a<\/strong>nums = [3,2,4], target = 6 <strong>\u8f93\u51fa\uff1a<\/strong>[1,2]<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><strong>\u8f93\u5165\uff1a<\/strong>nums = [3,3], target = 6 <strong>\u8f93\u51fa\uff1a<\/strong>[0,1]<\/p>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>2 &lt;= nums.length &lt;= 10<sup>4<\/sup><\/code><\/li>\n\n\n\n<li><code>-10<sup>9<\/sup> &lt;= nums[i] &lt;= 10<sup>9<\/sup><\/code><\/li>\n\n\n\n<li><code>-10<sup>9<\/sup> &lt;= target &lt;= 10<sup>9<\/sup><\/code><\/li>\n\n\n\n<li><strong>\u53ea\u4f1a\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7b54\u6848<\/strong><\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fdb\u9636\uff1a<\/strong>\u4f60\u53ef\u4ee5\u60f3\u51fa\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u5c0f\u4e8e&nbsp;<code>O(n<sup>2<\/sup>)<\/code>&nbsp;\u7684\u7b97\u6cd5\u5417\uff1f<\/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 has-link-color wp-elements-77d9babb6403b76b85ed1ff0e704a074\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u54c8\u5e0c\u8868<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u8bf6\uff0c\u54c8\u5e0c\u8868\u3002<\/p>\n\n\n\n<p>\u4e0b\u6807\u5f53value\u5b58\u4f1a\u65b9\u4fbf\u9700\u8981\uff0c\u7528key\u6765\u6bd4\u8f83\uff0c\u6700\u540e\u8fd4\u56de\u7684\u65f6\u5019\u5c31\u80fd\u76f4\u63a5\u8fd4\u56de\u4e24\u4e2avalue\uff08\u4e0b\u6807\uff09\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func twoSum(nums &#91;]int, target int) &#91;]int {\r\n  hashmap:=make(map&#91;int]int,len(nums))\r\n  for i:=0;i&lt;len(nums);i++{\r\n    if p,ok:=hashmap&#91;target-nums&#91;i]];ok{\r\n      return &#91;]int{p,i}\r\n    }\r\n    hashmap&#91;nums&#91;i]]=i\r\n  }\r\n  return nil\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u54c8\u5e0c\u8868<\/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\/5489"}],"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=5489"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/5489\/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=5489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=5489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=5489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}