From 2122858a08e32572c07fa5a641aa25a09f188542 Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:04 +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 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/3. 数组中重复的数字.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/notes/3. 数组中重复的数字.md b/notes/3. 数组中重复的数字.md index 4469fccf..7bdb6820 100644 --- a/notes/3. 数组中重复的数字.md +++ b/notes/3. 数组中重复的数字.md @@ -2,7 +2,7 @@ ## 题目链接 -[牛客网](https://www.nowcoder.com/practice/6fe361ede7e54db1b84adc81d09d8524?tpId=13&tqId=11203&tab=answerKey&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) ## 题目描述 @@ -28,13 +28,13 @@ Output: ```java -public int duplicate(int[] nums) { - for (int i = 0; i < nums.length; i++) { - while (nums[i] != i) { - if (nums[i] == nums[nums[i]]) { - return nums[i]; +public int findRepeatDocument(int[] documents) { + for (int i = 0; i < documents.length; i++) { + while (documents[i] != i) { + if (documents[i] == documents[documents[i]]) { + return documents[i]; } - swap(nums, i, nums[i]); + swap(documents, i, documents[i]); } } return -1; @@ -45,6 +45,5 @@ private void swap(int[] nums, int i, int j) { nums[i] = nums[j]; nums[j] = t; } - ```