{"id":66989,"date":"2025-05-03T14:23:35","date_gmt":"2025-05-03T06:23:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66989\/"},"modified":"2025-05-03T14:23:35","modified_gmt":"2025-05-03T06:23:35","slug":"%e4%b8%a4%e4%b8%aa%e6%95%b0%e7%bb%84%e4%b9%8b%e9%97%b4%e7%9a%84%e6%95%b0%e6%80%8e%e4%b9%88%e5%af%b9%e5%ba%94%e8%b5%b7%e6%9d%a5java-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66989\/","title":{"rendered":"\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u600e\u4e48\u5bf9\u5e94\u8d77\u6765java"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u53cc\u91cd\u5faa\u73af\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u5b57\u5bf9\u5e94\u8d77\u6765\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a o(n\u00b2)\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u904d\u5386\u7b2c\u4e00\u4e2a\u6570\u7ec4\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5143\u7d20\uff0c\u904d\u5386\u7b2c\u4e8c\u4e2a\u6570\u7ec4\uff0c\u5982\u679c\u5143\u7d20\u76f8\u7b49\uff0c\u5219\u5c06\u8fd9\u4e9b\u5143\u7d20\u5b58\u50a8\u5728\u5bf9\u5e94\u7684\u4f4d\u7f6e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111722185275405.jpg\" class=\"aligncenter\" title=\"\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u600e\u4e48\u5bf9\u5e94\u8d77\u6765java\u63d2\u56fe\" alt=\"\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u600e\u4e48\u5bf9\u5e94\u8d77\u6765java\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u5b57\u5bf9\u5e94\u8d77\u6765<\/strong><\/p>\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u91cd\u5faa\u73af\u4ee5 O(n\u00b2) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u5b57\u5bf9\u5e94\u8d77\u6765\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u904d\u5386\u7b2c\u4e00\u4e2a\u6570\u7ec4 arr1\u3002<\/li>\n<li>\u5bf9\u4e8e arr1 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u904d\u5386\u7b2c\u4e8c\u4e2a\u6570\u7ec4 arr2\u3002<\/li>\n<li>\u5982\u679c arr1 \u4e2d\u7684\u5143\u7d20\u7b49\u4e8e arr2 \u4e2d\u7684\u5143\u7d20\uff0c\u5219\u5c06\u8fd9\u4e9b\u5143\u7d20\u5b58\u50a8\u5728\u5bf9\u5e94\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>public static void main(String[] args) {\n    int[] arr1 = {1, 2, 3, 4, 5};\n    int[] arr2 = {6, 7, 8, 9, 10};\n\n    \/\/ \u521b\u5efa\u4e00\u4e2a\u4e0e arr1 \u540c\u5927\u5c0f\u7684\u6570\u7ec4\u6765\u5b58\u50a8\u5bf9\u5e94\u5173\u7cfb\n    int[] arr3 = new int[arr1.length];\n\n    \/\/ \u904d\u5386 arr1\n    for (int i = 0; i &lt; arr1.length; i++) {\n\n        \/\/ \u904d\u5386 arr2\n        for (int j = 0; j &lt; arr2.length; j++) {\n\n            \/\/ \u5982\u679c\u5143\u7d20\u76f8\u7b49\uff0c\u5219\u5b58\u50a8\u5bf9\u5e94\u5173\u7cfb\n            if (arr1[i] == arr2[j]) {\n                arr3[i] = arr2[j];\n            }\n        }\n    }\n\n    \/\/ \u6253\u5370\u5bf9\u5e94\u5173\u7cfb\n    for (int i = 0; i &lt; arr1.length; i++) {\n        System.out.println(\"arr1[\" + i + \"] = \" + arr3[i]);\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>arr1[0] = 6\narr1[1] = 7\narr1[2] = 8\narr1[3] = 9\narr1[4] = 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u600e\u4e48\u5bf9\u5e94\u8d77\u6765java\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u53cc\u91cd\u5faa\u73af\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u5b57\u5bf9\u5e94\u8d77\u6765\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a o(n\u00b2)\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u904d\u5386\u7b2c\u4e00\u4e2a\u6570\u7ec4\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5143\u7d20\uff0c\u904d\u5386\u7b2c\u4e8c\u4e2a\u6570\u7ec4\uff0c\u5982\u679c\u5143\u7d20\u76f8\u7b49\uff0c\u5219\u5c06\u8fd9\u4e9b\u5143\u7d20\u5b58\u50a8\u5728\u5bf9\u5e94\u7684\u4f4d\u7f6e\u3002 \u5982\u4f55\u5728 Java \u4e2d\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u5b57\u5bf9\u5e94\u8d77\u6765 \u65b9\u6cd5\uff1a \u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u91cd\u5faa\u73af\u4ee5 O(n\u00b2) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u6570\u5b57\u5bf9\u5e94\u8d77\u6765\u3002 \u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u904d\u5386\u7b2c\u4e00\u4e2a\u6570\u7ec4 arr1\u3002 \u5bf9\u4e8e arr1 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u904d\u5386\u7b2c\u4e8c\u4e2a\u6570\u7ec4 arr2\u3002 \u5982\u679c arr1 \u4e2d\u7684\u5143\u7d20\u7b49\u4e8e arr2 \u4e2d\u7684\u5143\u7d20\uff0c\u5219\u5c06\u8fd9\u4e9b\u5143\u7d20\u5b58\u50a8\u5728\u5bf9\u5e94\u7684\u4f4d\u7f6e\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a public static void main(String[] args) { int[] arr1 = {1, 2, 3, 4, 5}; int[] arr2 = {6, 7, 8, 9, 10}; \/\/ \u521b\u5efa\u4e00\u4e2a\u4e0e arr1 \u540c\u5927\u5c0f\u7684\u6570\u7ec4\u6765\u5b58\u50a8\u5bf9\u5e94\u5173\u7cfb int[] arr3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-66989","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=66989"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66989\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}