Update 数组相关.md

master
Omooo 5 years ago
parent e5d5f4ef33
commit 6f0c66271d
  1. 30
      blogs/Algorithm/剑指 Offer/数组相关.md

@ -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

Loading…
Cancel
Save