Skip to content

Commit 36bdbb8

Browse files
committed
solve contains-duplicate
1 parent 0fc7ec8 commit 36bdbb8

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

contains-duplicate/samcho0608.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.HashSet;
2+
3+
class Solution {
4+
// return: does any value appear more than once in the array
5+
// Time Complexity: O(n)
6+
// Space Complexity: O(n)
7+
public boolean containsDuplicate(int[] nums) {
8+
HashSet<Integer> uniqNums = new HashSet<>();
9+
10+
for(int num : nums) {
11+
if(!uniqNums.add(num)) return true;
12+
}
13+
14+
return false;
15+
}
16+
}

0 commit comments

Comments
 (0)