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 2e9b5fe commit 1b514fcCopy full SHA for 1b514fc
1 file changed
contains-duplicate/ykim7.js
@@ -0,0 +1,18 @@
1
+// Input: number[]
2
+// Output: boolean
3
+
4
+// 배열은 sorting되어 있지 않음.
5
+// Idea 1 : 이중 for loop으로 모든 값 비교 - O(n^2)
6
+// Idea 2 : nums를 sort 한 후 앞에서부터 두개씩 비교. 정렬 - O(nlogn)
7
+// Idea 3 : Hash table 로 추가하면서 저장. O(n) 검색 O(1) - O(n)
8
9
+const found_num = new Set();
10
11
+for (let i = 0; i < nums.length; i++) {
12
+ if (found_num.has(nums[i])) {
13
+ return true;
14
+ } else {
15
+ found_num.add(nums[i]);
16
+ }
17
+}
18
+return false;
0 commit comments