From c35bd32d69a27162ec8f48af85f67d0d36c7676f Mon Sep 17 00:00:00 2001 From: gyl1041 <37280353+gyl1041@users.noreply.github.com> Date: Tue, 10 Jun 2025 16:41:58 +0800 Subject: [PATCH] =?UTF-8?q?Update=203.=20=E6=95=B0=E7=BB=84=E4=B8=AD?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=9A=84=E6=95=B0=E5=AD=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这里第二次调用是多余的! duplicate 中每一次for循环的目的都是为了让 nums[i] == i ,也就是第 i 个位置等于 i 。 所以 while 循环要么找到重复数字return,要么结束循环后使得 nums[i] == i ,这时候再调用 swap(nums, i, nums[i]) 没有任何意义 --- ...1\207\215\345\244\215\347\232\204\346\225\260\345\255\227.md" | 1 - 1 file changed, 1 deletion(-) diff --git "a/notes/3. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.md" "b/notes/3. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.md" index babab09dfd..4469fccf0b 100644 --- "a/notes/3. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.md" +++ "b/notes/3. \346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.md" @@ -36,7 +36,6 @@ public int duplicate(int[] nums) { } swap(nums, i, nums[i]); } - swap(nums, i, nums[i]); } return -1; }