Skip to content

Commit fb50647

Browse files
committed
contains-duplicate solution
1 parent f78c3c6 commit fb50647

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

contains-duplicate/jjipper.ts

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

0 commit comments

Comments
 (0)