217. Contains Duplicate
Tags:
Easy
June 24, 2025
04:32 AM
No headings found
Loading content...
Related Posts
Leetcode
No headings found
Related Posts
Leetcode
Approach - Set
Time and space complexity
1function containsDuplicate(nums: number[]): boolean {
2 const set: Set<number> = new Set();
3 for (let i = 0; i < nums.length; i++) {
4 if (set.has(nums[i])) {
5 return true;
6 }
7 set.add(nums[i])
8 }
9 return false
10};