easy
arrays
bit-manipulation
Every value in nums appears exactly twice except one value that appears once. Return the unpaired value.
Input / output
- Input:
nums: integer[] - Output: the unique integer
Examples
[2,2,1]returns1.[4,1,2,1,2]returns4.
Constraints
1 <= nums.length <= 100,000nums.lengthis odd- The input satisfies the pairing rule
Follow-up Why does XOR remove paired values regardless of their order?
Examples
Example 1
Input: nums = [2,2,1]
Output: 1
Example 2
Input: nums = [4,1,2,1,2]
Output: 4
Example 3
Input: nums = [1]
Output: 1
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.