Leetcode Practice
LC 217. Contains Duplicate
- Last updated
- Reading time
- 1 min read
The problem
Solution
This problem is straightforward. By converting the array to a set, duplicates are removed. Then the sizes of the set and original array can be compared to see if duplicates were removed. If so, return true!
function containsDuplicate(nums: number[]): boolean {
return new Set(nums).size !== nums.length
}