Easy
LABContains Duplicate
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
FUNCTION SHAPE
→
unknownSOLUTION NOTE
Very simple - if there is any duplicate, the set will combine those duplicates into a single element so the length will be less than the original.
Reveal reference solution +
pythonREFERENCE
def containsDuplicate(self, nums: List[int]) -> bool:
return len(set(nums)) < len(nums)Time
O(n)Space
O(n)