Skip to content

Commit 22e0e0c

Browse files
committed
1: contains duplicate
1 parent ee1ad8e commit 22e0e0c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

contains-duplicate/whewchews.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function containsDuplicate(nums: number[]): boolean {
2+
const dict: Set<number> = new Set();
3+
4+
// O(n)
5+
for (let i = 0; i <= nums.length; i++) {
6+
const n = nums[i];
7+
8+
// O(1)
9+
if (dict.has(n)) return true;
10+
// O(1)
11+
dict.add(n);
12+
}
13+
14+
return false;
15+
}
16+
17+
// TC: O(N)
18+
// SC: O(N)

0 commit comments

Comments
 (0)