LeetCode: Contains Duplicate Solution

Set

Approach

Compare size of set created from array and the length of original array

Implementation

1var containsDuplicate = function (nums) {
2 return new Set(nums).size !== nums.length
3}

References

Original problem

Similar problems

Contains Duplicate II

Contains Duplicate III

Make Array Zero by Subtracting Equal Amounts

Comments

Loading comments...

Tags

leetcode

neetcode

array

hash table

Next Post

LeetCode: Rotate Array

Stale solution might be time-limit exceeded someday

HoningJS

Search Posts