Sign inEnroll free
DSA Visualizer · 25 visualizationsContains Duplicate
EasyArrays & Hashing

Contains Duplicate

Given an integer array nums, return true if any value appears at least twice, and false if every element is distinct.

The step-through player is coming for this one. Two Sum has the full animation today; the rest are being authored in the admin.
Pythontime O(n) · space O(n)
def containsDuplicate(nums: list[int]) -> bool:
    return len(nums) != len(set(nums))
Two Sum is free. Enroll to unlock every visualization and save where you stopped.Enroll free
Watch the video walkthrough