We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ee1ad8e commit bacf40eCopy full SHA for bacf40e
โcontains-duplicate/taekwon-dev.javaโ
@@ -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