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 c64c254 commit 1fca4dfCopy full SHA for 1fca4df
contains-duplicate/sujeong-dev.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {boolean}
4
+ */
5
+
6
+// for loof: O(n)
7
+var containsDuplicate = function (nums) {
8
+ let indices = {};
9
+ nums.forEach((num, index) => {
10
+ indices[num] = index;
11
+ });
12
13
+ for (let i = 0; i < nums.length; i++) {
14
+ if (nums[i] in indices && indices[nums[i]] !== i) return true;
15
+ }
16
17
+ return false;
18
+};
19
20
+// size 속성: O(1)
21
22
+ const indices = new Set(nums);
23
24
+ if (indices.size !== nums.length) return true;
25
26
27
0 commit comments