Back to Arrays & Hashing
Arrays & Hashing
Easy

Contains Duplicate

LAB

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

unknown
SOLUTION 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)
TimeO(n)
SpaceO(n)
Open on LeetCode
00:00
Local tests unavailableRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.