1. a ^ b ^ b = a.
  2. c ^ c = 0.
1
2
3
4
5
6
7
8
9
class Solution {
public int singleNumber(int[] nums) {
int res = nums[0];
for (int i = 1; i < nums.length; ++i) {
res ^= nums[i];
}
return res;
}
}