Skip to content

Commit f67c428

Browse files
committed
contains-duplicate solution
1 parent ee1ad8e commit f67c428

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

contains-duplicate/f-exuan21.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// time : O(n)
2+
// space : O(n)
3+
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
HashSet<Integer> set = new HashSet<>();
7+
for(int i : nums) {
8+
if(set.contains(i)) {
9+
return true;
10+
}
11+
set.add(i);
12+
}
13+
return false;
14+
}
15+
}

0 commit comments

Comments
 (0)