For every pair (x, x), x ^ x = 0, and 0 is the identity for ^, and ^ is commutative. So reduce the entire list of numbers with ^ and only the missing number remains.

```
class Solution {
public:
int singleNumber(vector<int>& nums) {
int result = 0;
for (int n : nums) {
result ^= n;
}
return result;
}
};
```