Back to problems Solve on LeetCode → Next: Two Sum →

Contains Duplicate

Hash Set Membership Check — Early Exit

LeetCode 217 • Easy • Arrays & Hashing

Input: nums = [5, 3, 8, 1, 3, 9, 2]  →  Output: true  (3 appears at index 1 and index 4)

TimeO(n)single pass
SpaceO(n)hash set
Checked: 0/7 Set size: 0 Lookups: 0
Current element
In set (safe)
Duplicate found!
All unique
Current
Set
{ }
Result
Ready
Press Play to watch the algorithm, or Step to advance one operation at a time.
For each element, check: is it already in the set? If yes → duplicate. If no → add it and move on.