Recover the Value Left after Pair Cancellation
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
In a nonempty integer array, every distinct value occurs exactly twice except one value that occurs once. Return the single-occurrence value. Use linear time and constant extra space.
```cpp
int singleNumber(vector<int>& nums);
```
### Examples
```text
Input: nums = [-7,4,-7,4,9]
Output: 9
```
```text
Input: nums = [0]
Output: 0
```
### Constraints
- Length is between 1 and 30000.
- Values are between -30000 and 30000, inclusive.
- Exactly one value occurs once and every other value occurs twice.
Overview: Recover the sole unpaired integer by XOR cancellation in linear time and constant extra space.