{"id":561,"date":"2026-07-04T09:33:39","date_gmt":"2026-07-04T01:33:39","guid":{"rendered":"https:\/\/mitongxue.cn\/?p=561"},"modified":"2026-07-04T09:33:39","modified_gmt":"2026-07-04T01:33:39","slug":"%e4%b8%a4%e6%95%b0%e4%b9%8b%e5%92%8c","status":"publish","type":"post","link":"https:\/\/mitongxue.cn\/index.php\/2026\/07\/04\/%e4%b8%a4%e6%95%b0%e4%b9%8b%e5%92%8c\/","title":{"rendered":"\u4e24\u6570\u4e4b\u548c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c&nbsp;<code>target<\/code>\uff0c\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa&nbsp;<strong>\u548c\u4e3a\u76ee\u6807\u503c&nbsp;<\/strong><em><code>target<\/code><\/em>&nbsp; \u7684\u90a3&nbsp;<strong>\u4e24\u4e2a<\/strong>&nbsp;\u6574\u6570\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848\uff0c\u5e76\u4e14\u4f60\u4e0d\u80fd\u4f7f\u7528\u4e24\u6b21\u76f8\u540c\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [2,7,11,15], target = 9\n<strong>\u8f93\u51fa\uff1a<\/strong>[0,1]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a nums[0] + nums[1] == 9 \uff0c\u8fd4\u56de [0, 1] \u3002\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [3,2,4], target = 6\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,2]\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [3,3], target = 6\n<strong>\u8f93\u51fa\uff1a<\/strong>[0,1]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">LeetCode\u548c\u725b\u5ba2\u8f93\u51fa\u65b9\u5f0f\u5b58\u5728\u5dee\u5f02\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * @param {number&#91;]} nums\n * @param {number} target\n * @return {number&#91;]}\n *\/\n\nvar twoSum = function(nums, target) {\n    const result = &#91;];\n    for(let i=0;i&lt;nums.length-1;i++){\n        \/\/console.log(i);\n        for(let j=i+1;j&lt;=nums.length-1;j++){\n            if(nums&#91;i]+nums&#91;j]===target){\n                \/\/console.log(&#91;i,j]);\n                result.push(i);\n                result.push(j);\n                return result;\n            }\n        }\n    }\n    return result;\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var twoSum = function(nums, target) {\n    let map = new Map();\n    for(let i=0;i&lt;nums.length;i++){\n        let need = target - nums&#91;i];\n        if(map.has(need)){\n            \/\/ \u76f4\u63a5\u8fd4\u56de\u6570\u7ec4\uff0c\u7cfb\u7edf\u81ea\u52a8\u6821\u9a8c\n            return &#91;map.get(need), i];\n        }\n        map.set(nums&#91;i], i);\n    }\n    return &#91;];\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;nums&nbsp;\u548c..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,11,23],"tags":[],"class_list":["post-561","post","type-post","status-publish","format-standard","hentry","category-js","category-front","category-23"],"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"author_info":{"info":["\u9648 \u67d0\u4eba"]},"category_info":"<a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/js\/\" rel=\"category tag\">JS<\/a> <a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/\" rel=\"category tag\">\u524d\u7aef<\/a> <a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/%e8%af%95%e9%a2%98\/\" rel=\"category tag\">\u8bd5\u9898<\/a>","tag_info":"\u8bd5\u9898","comment_count":"0","_links":{"self":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":1,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":562,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/561\/revisions\/562"}],"wp:attachment":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}