Skip to content

Commit 6027156

Browse files
committed
auto commit
1 parent 061b375 commit 6027156

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

notes/3. 数组中重复的数字.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 题目链接
44

5-
[牛客网](https://www.nowcoder.com/practice/623a5ac0ea5b4e5f95552655361ae0a8?tpId=13&tqId=11203&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
5+
[牛客网](https://www.nowcoder.com/practice/6fe361ede7e54db1b84adc81d09d8524?tpId=13&tqId=11203&tab=answerKey&from=cyc_github)
66

77
## 题目描述
88

@@ -28,24 +28,24 @@ Output:
2828

2929

3030
```java
31-
public boolean duplicate(int[] nums, int length, int[] duplication) {
32-
if (nums == null || length <= 0)
33-
return false;
34-
for (int i = 0; i < length; i++) {
31+
public int duplicate(int[] nums) {
32+
for (int i = 0; i < nums.length; i++) {
3533
while (nums[i] != i) {
3634
if (nums[i] == nums[nums[i]]) {
37-
duplication[0] = nums[i];
38-
return true;
35+
return nums[i];
3936
}
4037
swap(nums, i, nums[i]);
4138
}
39+
swap(nums, i, nums[i]);
4240
}
43-
return false;
41+
return -1;
4442
}
4543

4644
private void swap(int[] nums, int i, int j) {
4745
int t = nums[i];
4846
nums[i] = nums[j];
4947
nums[j] = t;
5048
}
49+
5150
```
51+

0 commit comments

Comments
 (0)