Skip to content

Commit 8ca17f7

Browse files
committed
contains-duplicate solution
1 parent 651d248 commit 8ca17f7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

contains-duplicate/toychip.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+
import java.util.Set;
3+
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
Set<Integer> answer = new HashSet<>();
7+
for (int num : nums) {
8+
if (!answer.contains(num)) {
9+
answer.add(num);
10+
} else {
11+
return true;
12+
}
13+
}
14+
return false;
15+
}
16+
}

0 commit comments

Comments
 (0)