Single Number
Every integer in nums occurs twice except one that occurs once. Return the unpaired value using linear time and constant auxiliary space.
Example 1
nums = [4,2,4,9,2]9Explanation
The pairs of 4 and 2 cancel under XOR, leaving 9.
Example 2
nums = [-1]-1Explanation
A singleton is its own unpaired value, including a negative value.
Example 3
nums = [0,3,3]0Explanation
The 3 pair cancels, leaving unique value zero.
Constraints
- 1 <= len(nums) <= 30000
- Values are signed 32-bit integers
Function contract
singleNumberArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[4,2,4,9,2]