Skip to content

Commit f989781

Browse files
committed
contains-duplicate solution
1 parent f5663dc commit f989781

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contains-duplicate/chjung99.java

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

0 commit comments

Comments
 (0)