Skip to content

Commit 4df0570

Browse files
committed
feat: contains-duplicate
1 parent f291ae8 commit 4df0570

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

contains-duplicate/choidabom.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://leetcode.com/problems/contains-duplicate/description/
2+
3+
// TC: O(n)
4+
// SC: O(n)
5+
6+
function containsDuplicate(nums: number[]): boolean {
7+
const set = new Set(nums)
8+
return set.size !== nums.length
9+
};
10+
11+
function containsDuplicate(nums: number[]): boolean {
12+
const set = new Set()
13+
14+
for (const num of nums){
15+
if (set.has(num)){
16+
return true
17+
}
18+
set.add(num)
19+
}
20+
21+
return false
22+
}
23+
24+
console.log(containsDuplicate([1,1,1,3,3,4,3,2,4,2]))

0 commit comments

Comments
 (0)