Skip to content

Commit 2706dea

Browse files
committed
Contains Duplicate
1 parent ee1ad8e commit 2706dea

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

contains-duplicate/sunjae95.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @description
3+
* time complexity: O(n)
4+
* space complexity: O(n)
5+
* approach/strategy:
6+
* 1. brute force + hash table
7+
*/
8+
9+
/**
10+
* @param {number[]} nums
11+
* @return {boolean}
12+
*/
13+
var containsDuplicate = function (nums) {
14+
const hashTable = new Set();
15+
16+
for (const num of nums) {
17+
if (hashTable.has(num)) return true;
18+
hashTable.add(num);
19+
}
20+
21+
return false;
22+
};

0 commit comments

Comments
 (0)