Update Leetcode 题解 - 哈希表.md
This commit is contained in:
parent
f84b140418
commit
4a56358678
@ -45,13 +45,19 @@ public int[] twoSum(int[] nums, int target) {
|
||||
|
||||
[Leetcode](https://leetcode.com/problems/contains-duplicate/description/) / [力扣](https://leetcode-cn.com/problems/contains-duplicate/description/)
|
||||
|
||||
|
||||
```java
|
||||
public boolean containsDuplicate(int[] nums) {
|
||||
Set<Integer> set = new HashSet<>();
|
||||
for (int num : nums) {
|
||||
set.add(num);
|
||||
//if set.containsKey(num){
|
||||
// return true;
|
||||
//}
|
||||
//set.add(num);
|
||||
}
|
||||
return set.size() < nums.length;
|
||||
//return false;
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user