|
|
@ -17,6 +17,36 @@ class Solution { |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
class Solution { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int findRepeatNumber(int[] nums) { |
|
|
|
|
|
|
|
Arrays.sort(nums); |
|
|
|
|
|
|
|
for (int i = 0; i < nums.length - 1; i++) { |
|
|
|
|
|
|
|
if (nums[i] == nums[i + 1]) { |
|
|
|
|
|
|
|
return nums[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
class Solution { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int findRepeatNumber(int[] nums) { |
|
|
|
|
|
|
|
HashSet<Integer> set = new HashSet<>(); |
|
|
|
|
|
|
|
for (int i : nums) { |
|
|
|
|
|
|
|
if (!set.add(i)) { |
|
|
|
|
|
|
|
return i; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
[04. 二维数组中的查找](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) |
|
|
|
[04. 二维数组中的查找](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|