点击打开链接
class Solution {
public:
vector<int> singleNumber(vector<int>& nums) {
int diff = accumulate(nums.begin(), nums.end(),0, bit_xor<int>());
diff &= -diff; //从低位到高位第一个是1的某一位的操作。
vector<int> res(2,0);
for(int i=0; i<nums.size();i++){
if(nums[i]&diff){
res[0] ^= nums[i];
}
else{
res[1] ^= nums[i];
}
}
return res;
}
};