Skip to content

Commit 0c04f6e

Browse files
committed
Contains Duplicate
1 parent 67949d5 commit 0c04f6e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Runtime: 10 ms(Beats: 89.16 %)
3+
Time Complexity: O(n)
4+
- HashSet r/w : O(1)
5+
- nums iteration : ( O(1) + O(1) ) * n = O(n)
6+
7+
Memory: 58.63 MB(Beats: 22.32 %)
8+
Space Complexity: O(n)
9+
*/
10+
11+
12+
class Solution {
13+
public boolean containsDuplicate(int[] nums) {
14+
Set<Integer> set = new HashSet<>();
15+
16+
for (int num: nums) {
17+
if (set.contains(num)) {
18+
return true;
19+
}
20+
21+
set.add(num);
22+
}
23+
24+
return false;
25+
}
26+
}

0 commit comments

Comments
 (0)