Contains duplicate
Warm-up · Write code · about 8 min
Given an integer array nums, return true if some value appears at least twice, and false if every value is distinct.
Scan the array once and keep a set of the values read so far.
Example 1
Input:
[[5,1,8,3,1,6]]
Output:
true
1 appears at index 1 and index 4.
Example 2
Input:
[[4,2,6]]
Output:
false
Constraints
- 0 ≤ nums.length ≤ 10,000
- -1,000,000 ≤ nums[i] ≤ 1,000,000
Learn the idea first: Hash maps for lookup and counting, a visual lesson.
More Hash maps for lookup and counting problems
- Fill the seen-set Warm-up
- Isomorphic strings Standard
- Subarray sums divisible by k Standard
- Longest consecutive sequence Challenge