0260.cpp (321B)
1 class Solution { 2 public: 3 vector<int> singleNumber(const vector<int> &nums) { 4 long long diff = accumulate(begin(nums), end(nums), 0, bit_xor<int>()); 5 diff &= -diff; 6 vector<int> res = {0, 0}; 7 for (const int n : nums) 8 res[(n & diff) == 0] ^= n; 9 return res; 10 } 11 };