easy
arrays
hashmap
Return true when any value occurs at least twice in nums; otherwise return false.
Input / output
- Input:
nums: integer[] - Output: boolean
Examples
[1,2,3,1]returnstrue.[1,2,3,4]returnsfalse.
Constraints
0 <= nums.length <= 100,000-1,000,000,000 <= nums[i] <= 1,000,000,000
Follow-up Compare a hash set with sorting when memory is constrained or modifying the input is allowed.
Examples
Example 1
Input: nums = [1,2,3,1]
Output: true
Example 2
Input: nums = [1,2,3,4]
Output: false
Example 3
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.