0%

LeetCode-217

题目

Snipaste_2020-12-13_09-28-54.png

结果

Snipaste_2020-12-13_09-28-49.png

代码

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> set = new HashSet<>();
for (int num : nums) {
if (!set.add(num)) {
return true;
}
}
return false;
}
}

复杂度

时间复杂度:O(n)

空间复杂度:O(n)