Skip to content

Commit cf40e6a

Browse files
committed
contains duplicate solution
1 parent 53ce7c7 commit cf40e6a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

contains-duplicate/nancyel.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* time complexity: O(n)
3+
* space complexity: O(n)
4+
*/
5+
function containsDuplicate(nums: number[]): boolean {
6+
const seen = new Set();
7+
for (let num of nums) {
8+
if (seen.has(num)) {
9+
return true;
10+
}
11+
seen.add(num);
12+
}
13+
return false;
14+
}

0 commit comments

Comments
 (0)