{"id":66593,"date":"2026-01-26T23:17:02","date_gmt":"2026-01-26T15:17:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/66593.html"},"modified":"2026-01-26T23:17:02","modified_gmt":"2026-01-26T15:17:02","slug":"hot-100-%e7%ac%ac%e4%b8%80%e9%a2%981-%e4%b8%a4%e6%95%b0%e4%b9%8b%e5%92%8c%e6%b1%82%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/66593.html","title":{"rendered":"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3"},"content":{"rendered":"<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c\u00a0target&#xff0c;\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u00a0\u548c\u4e3a\u76ee\u6807\u503c\u00a0target\u00a0 \u7684\u90a3\u00a0\u4e24\u4e2a\u00a0\u6574\u6570&#xff0c;\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848&#xff0c;\u5e76\u4e14\u4f60\u4e0d\u80fd\u4f7f\u7528\u4e24\u6b21\u76f8\u540c\u7684\u5143\u7d20\u3002<\/p>\n<p>\u66b4\u529b\u89e3\u6cd501<\/p>\n<p>class Solution {<br \/>\n    public int[] twoSum(int[] nums, int target) {<br \/>\n        for(int i&#061;0 ; i&lt;nums.length;i&#043;&#043;){<br \/>\n            if(index(nums,target-nums[i],i&#043;1)&gt;&#061;0){<br \/>\n                int number &#061;index(nums,target-nums[i],i&#043;1);<br \/>\n                int arr[]&#061;{i,number};<br \/>\n                return arr;<br \/>\n            }<br \/>\n        }<br \/>\n        int arr[]&#061;new int[2];<br \/>\n        return arr;<br \/>\n    }<br \/>\n    public int index(int[] nums, int num, int startIndex){<br \/>\n       for(int i&#061;startIndex ; i&lt;nums.length;i&#043;&#043;){<br \/>\n            if(num &#061;&#061; nums[i]){<br \/>\n                return i;<br \/>\n            }<br \/>\n        }<br \/>\n     return -1;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u4f18\u5316\u7248\u66b4\u529b\u679a\u4e3e\u89e3\u6cd5&#xff08;\u5b98\u65b9\u89e3\u6cd5&#xff09;<\/p>\n<p>\u601d\u8def\u53ca\u7b97\u6cd5<\/p>\n<p>\u6700\u5bb9\u6613\u60f3\u5230\u7684\u65b9\u6cd5\u662f\u679a\u4e3e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570 x&#xff0c;\u5bfb\u627e\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728 target &#8211; x\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528\u904d\u5386\u6574\u4e2a\u6570\u7ec4\u7684\u65b9\u5f0f\u5bfb\u627e target &#8211; x \u65f6&#xff0c;\u9700\u8981\u6ce8\u610f\u5230\u6bcf\u4e00\u4e2a\u4f4d\u4e8e x \u4e4b\u524d\u7684\u5143\u7d20\u90fd\u5df2\u7ecf\u548c x \u5339\u914d\u8fc7&#xff0c;\u56e0\u6b64\u4e0d\u9700\u8981\u518d\u8fdb\u884c\u5339\u914d\u3002\u800c\u6bcf\u4e00\u4e2a\u5143\u7d20\u4e0d\u80fd\u88ab\u4f7f\u7528\u4e24\u6b21&#xff0c;\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u5728 x \u540e\u9762\u7684\u5143\u7d20\u4e2d\u5bfb\u627e target &#8211; x\u3002<\/p>\n<p>class Solution {<br \/>\n    public int[] twoSum(int[] nums, int target) {<br \/>\n        int n &#061; nums.length;<br \/>\n        for (int i &#061; 0; i &lt; n; &#043;&#043;i) {<br \/>\n            for (int j &#061; i &#043; 1; j &lt; n; &#043;&#043;j) {<br \/>\n                if (nums[i] &#043; nums[j] &#061;&#061; target) {<br \/>\n                    return new int[]{i, j};<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        return new int[0];<br \/>\n    }<br \/>\n}<\/p>\n<p>\u54c8\u5e0c\u8868<\/p>\n<p>\u6ce8\u610f\u5230\u65b9\u6cd5\u4e00\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u8f83\u9ad8\u7684\u539f\u56e0\u662f\u5bfb\u627e target &#8211; x \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u8fc7\u9ad8\u3002\u56e0\u6b64&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u79cd\u66f4\u4f18\u79c0\u7684\u65b9\u6cd5&#xff0c;\u80fd\u591f\u5feb\u901f\u5bfb\u627e\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u76ee\u6807\u5143\u7d20\u3002\u5982\u679c\u5b58\u5728&#xff0c;\u6211\u4eec\u9700\u8981\u627e\u51fa\u5b83\u7684\u7d22\u5f15\u3002<\/p>\n<p>\u4f7f\u7528\u54c8\u5e0c\u8868&#xff0c;\u53ef\u4ee5\u5c06\u5bfb\u627e target &#8211; x \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u964d\u4f4e\u5230\u4ece O(N) \u964d\u4f4e\u5230 O(1)\u3002<\/p>\n<p>\u8fd9\u6837\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u54c8\u5e0c\u8868&#xff0c;\u5bf9\u4e8e\u6bcf\u4e00\u4e2a x&#xff0c;\u6211\u4eec\u9996\u5148\u67e5\u8be2\u54c8\u5e0c\u8868\u4e2d\u662f\u5426\u5b58\u5728 target &#8211; x&#xff0c;\u7136\u540e\u5c06 x \u63d2\u5165\u5230\u54c8\u5e0c\u8868\u4e2d&#xff0c;\u5373\u53ef\u4fdd\u8bc1\u4e0d\u4f1a\u8ba9 x \u548c\u81ea\u5df1\u5339\u914d\u3002<\/p>\n<p>class Solution {<br \/>\n    public int[] twoSum(int[] nums, int target) {<br \/>\n        \/\/ \u4f7f\u7528 HashMap \u5b58\u50a8 &lt;\u503c, \u7d22\u5f15&gt;<br \/>\n        Map&lt;Integer, Integer&gt; map &#061; new HashMap&lt;&gt;();<\/p>\n<p>        for(int i &#061; 0; i &lt; nums.length; i&#043;&#043;){<br \/>\n            int complement &#061; target &#8211; nums[i];<\/p>\n<p>            \/\/ \u68c0\u67e5\u5dee\u503c\u662f\u5426\u5df2\u5b58\u5728<br \/>\n            if(map.containsKey(complement)){<br \/>\n                return new int[]{map.get(complement), i};<br \/>\n            }<\/p>\n<p>            \/\/ \u5c06\u5f53\u524d\u503c\u548c\u7d22\u5f15\u5b58\u5165 map<br \/>\n            map.put(nums[i], i);<br \/>\n        }<\/p>\n<p>        return new int[2]; \/\/ \u9898\u76ee\u4fdd\u8bc1\u6709\u89e3<br \/>\n    }<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c\u00a0target&#xff0c;\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u00a0\u548c\u4e3a\u76ee\u6807\u503c\u00a0target\u00a0 \u7684\u90a3\u00a0\u4e24\u4e2a\u00a0\u6574\u6570&#xff0c;\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848&#xff0c;\u5e76\u4e14\u4f60\u4e0d\u80fd\u4f7f\u7528\u4e24\u6b21\u76f8\u540c\u7684\u5143\u7d20\u3002\u66b4\u529b\u89e3\u6cd501class Solution {public int[] twoSum(int[] nums, int target) {for(int i0 ; i&lt;nums.length;i){if(index(nums,t<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2692,1813,427],"topic":[],"class_list":["post-66593","post","type-post","status-publish","format-standard","hentry","category-server","tag-leetcode","tag-1813","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/66593.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c\u00a0target&#xff0c;\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u00a0\u548c\u4e3a\u76ee\u6807\u503c\u00a0target\u00a0 \u7684\u90a3\u00a0\u4e24\u4e2a\u00a0\u6574\u6570&#xff0c;\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848&#xff0c;\u5e76\u4e14\u4f60\u4e0d\u80fd\u4f7f\u7528\u4e24\u6b21\u76f8\u540c\u7684\u5143\u7d20\u3002\u66b4\u529b\u89e3\u6cd501class Solution {public int[] twoSum(int[] nums, int target) {for(int i0 ; i&lt;nums.length;i){if(index(nums,t\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/66593.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-26T15:17:02+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/66593.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/66593.html\",\"name\":\"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-26T15:17:02+00:00\",\"dateModified\":\"2026-01-26T15:17:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/66593.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/66593.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/66593.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/66593.html","og_locale":"zh_CN","og_type":"article","og_title":"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c\u00a0target&#xff0c;\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u00a0\u548c\u4e3a\u76ee\u6807\u503c\u00a0target\u00a0 \u7684\u90a3\u00a0\u4e24\u4e2a\u00a0\u6574\u6570&#xff0c;\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848&#xff0c;\u5e76\u4e14\u4f60\u4e0d\u80fd\u4f7f\u7528\u4e24\u6b21\u76f8\u540c\u7684\u5143\u7d20\u3002\u66b4\u529b\u89e3\u6cd501class Solution {public int[] twoSum(int[] nums, int target) {for(int i0 ; i&lt;nums.length;i){if(index(nums,t","og_url":"https:\/\/www.wsisp.com\/helps\/66593.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-26T15:17:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/66593.html","url":"https:\/\/www.wsisp.com\/helps\/66593.html","name":"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-26T15:17:02+00:00","dateModified":"2026-01-26T15:17:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/66593.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/66593.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/66593.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"hot 100 \u7b2c\u4e00\u98981. \u4e24\u6570\u4e4b\u548c\u6c42\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/66593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=66593"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/66593\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=66593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=66593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=66593"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=66593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}