Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed Mar 18, 2021
1 parent 061b375 commit 6027156
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions notes/3. 数组中重复的数字.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 题目链接

[牛客网](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)
[牛客网](https://www.nowcoder.com/practice/6fe361ede7e54db1b84adc81d09d8524?tpId=13&tqId=11203&tab=answerKey&from=cyc_github)

## 题目描述

Expand All @@ -28,24 +28,24 @@ Output:


```java
public boolean duplicate(int[] nums, int length, int[] duplication) {
if (nums == null || length <= 0)
return false;
for (int i = 0; i < length; i++) {
public int duplicate(int[] nums) {
for (int i = 0; i < nums.length; i++) {
while (nums[i] != i) {
if (nums[i] == nums[nums[i]]) {
duplication[0] = nums[i];
return true;
return nums[i];
}
swap(nums, i, nums[i]);
}
swap(nums, i, nums[i]);
}
return false;
return -1;
}

private void swap(int[] nums, int i, int j) {
int t = nums[i];
nums[i] = nums[j];
nums[j] = t;
}

```

0 comments on commit 6027156

Please sign in to comment.