LeetCode 217 ·
Easy
Contains Duplicate
Return true if any value appears at least twice in the array.
Try it
Step through the core mechanic. The simulator below runs the hash map shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Hash map — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Stream into a hash set; if an insert finds the value already present, return true. Equivalent: compare len(set(nums)) with len(nums).
| Aspect | Value |
|---|---|
| Pattern | Hash map |
| Recognise it by | Any value repeats? Membership in O(1). |
| Time complexity | O(n) |
| Space complexity | O(n) |
| Difficulty | Easy |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.