Skip to content

Commit bacf40e

Browse files
committed
contains-duplicate
1 parent ee1ad8e commit bacf40e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
/**
3+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(N)
4+
* - ์ตœ์•…์˜ ๊ฒฝ์šฐ ์ฃผ์–ด์ง„ ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ์›์†Œ๊นŒ์ง€ ์ฒดํฌํ•ด์•ผ ํ•จ.
5+
* - ์ค‘๋ณต ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•ด Set ์„ ํƒํ•œ ์ด์œ 
6+
* - O(1) ์œผ๋กœ ํƒ์ƒ‰ ๊ฐ€๋Šฅ
7+
* - ๋ฐ์ดํ„ฐ ์ˆœ์„œ ๋ณด์žฅ ํ•„์š” ์—†์Œ
8+
*/
9+
public boolean containsDuplicate(int[] nums) {
10+
HashSet<Integer> set = new HashSet<>();
11+
for (int num: nums) {
12+
if (set.contains(num)) {
13+
return true;
14+
}
15+
set.add(num);
16+
}
17+
return false;
18+
}
19+
}

0 commit comments

Comments
ย (0)