Skip to content

Commit f51e1bd

Browse files
Jaewon LeeJaewon Lee
authored andcommitted
217. Contains Duplicate
1 parent 53ce7c7 commit f51e1bd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

contains-duplicate/mumunuu.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.HashSet;
2+
import java.util.Set;
3+
4+
5+
class Solution {
6+
7+
/**
8+
*
9+
* Set 판단으로 O(n)
10+
*
11+
* */
12+
public boolean containsDuplicate(int[] nums) {
13+
14+
Set<Integer> set = new HashSet<>();
15+
16+
for (int num : nums) {
17+
18+
boolean isAdded = set.add(num);
19+
20+
if (!isAdded) {
21+
return true;
22+
}
23+
}
24+
25+
return false;
26+
27+
}
28+
}

0 commit comments

Comments
 (0)