Skip to content

Commit 6fdb0fa

Browse files
KJHKJH
authored andcommitted
solve: contains-duplicate
1 parent 53ce7c7 commit 6fdb0fa

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

contains-duplicate/reach0908.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)