Contains Duplicate
Part of Practice: Hashing Warmups
You are given an array of integers nums. Decide whether any value shows up more than once. Return true if at least one value appears two or more times, and false if every value is distinct.
The array can hold up to 100,000 numbers, and values can be large positive or negative integers, so an answer that compares every pair will be too slow in the worst case.
Examples
- Input:
- nums = [1, 2, 3, 1]
- Output:
- true
The value 1 appears at index 0 and again at index 3.
- Input:
- nums = [1, 2, 3, 4]
- Output:
- false
All four values are different.
- Input:
- nums = [1, 1, 1, 3, 3, 4, 3, 2, 4, 2]
- Output:
- true
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.