mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 16:06:24 +00:00
Update 3. 数组中重复的数字.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user