Contains Duplicate
- Array
- Hash Set
Given an integer array nums, return true if any value appears at least twice. Return false when every value is distinct.
Repeated positive value
- Input
"nums": [14, -3, 8, 14, 22]
- Output
true
Explanation: The value 14 occurs at both the beginning and index 3.
Mixed distinct values
- Input
"nums": [6, -4, 19, 0, 27]
- Output
false
Explanation: No two positions contain the same integer.
Constraints
- 1 <= nums.length <= 100,000
- -1,000,000,000 <= nums[i] <= 1,000,000,000
Follow-up
Can you solve the problem in O(n) expected time with O(n) additional space?