Skip to content

Commit b5cc1da

Browse files
committed
contains duplicate solution
1 parent 81854bf commit b5cc1da

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

contains-duplicate/ohgyulim.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.*;
2+
/* 시간 복잡도: O(N), nums.length를 n이라고 할 때, 시간 복잡도는 O(N)
3+
* HashSet
4+
* - contains: O(1)
5+
* - add: O(1)
6+
*
7+
* 공간 복잡도: O(N), Set에 최대 n개의 요소를 저장할 수 있음
8+
*/
9+
class Solution {
10+
public boolean containsDuplicate(int[] nums) {
11+
Set<Integer> set = new HashSet<>();
12+
for (int num : nums) {
13+
if (set.contains(num)) return true;
14+
set.add(num);
15+
}
16+
return false;
17+
}
18+
}

0 commit comments

Comments
 (0)