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 53ce7c7 commit 6fdb0faCopy full SHA for 6fdb0fa
contains-duplicate/reach0908.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @description
3
+ * time complexity: O(n)
4
+ * space complexity: O(n)
5
+ * 풀이 방법:
6
+ * - 주어진 배열을 순회하며 해쉬테이블을 구성하고 해쉬 테이블에 이미 값이 있는 경우 early return 을 통해 중복됨을 반환
7
+ * @param {number[]} nums
8
+ * @return {boolean}
9
+ */
10
+const containsDuplicate = function (nums) {
11
+ const hashTable = new Set();
12
+ for (let i = 0; i < nums.length; i++) {
13
+ if (hashTable.has(nums[i])) {
14
+ return true;
15
+ }
16
+ hashTable.set(nums[i], i);
17
18
+ return false;
19
+};
0 commit comments