Leetcode 260 Solution
This article provides solution to leetcode question 260 (single-number-iii)
Access this page by simply typing in "lcs 260" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/single-number-iii
Solution
class Solution {
public:
vector<int> singleNumber(vector<int>& nums) {
int diff = 0;
for (int i = 0; i < nums.size(); i++)
diff ^= nums[i];
diff &= -diff;
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;
}
};