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 81854bf commit b5cc1daCopy full SHA for b5cc1da
contains-duplicate/ohgyulim.java
@@ -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