class Solution {
public:
vector<int> singleNumber(vector<int>& nums) {
int s = 0;
for (auto num : nums) s ^= num;
int k = 0;
while (!(s >> k & 1)) k++;
int n1 = 0;
for (auto num : nums) {
if (num >> k & 1) n1 ^= num;
}
// If s == a ^ b, n1 == a, then s ^ n1 == a ^ b ^ a == b
return vector<int>({n1, s ^ n1});
}
};