思路
1.0与任何数异或都为原数:0^n = n;
2.自己与自己异或为0 :n^n = 0 ;
3.异或具有交换律 : a^b^c = a^c^b
时间复杂度$O(n)$ 空间复杂度$O(1)$
class Solution {
public:
int singleNumber(vector<int>& nums) {
int sum = 0;
for(auto it : nums) sum = sum^it;
return sum;
}
};