Using XOR soln C++


Main idea behind using XOR is:-
a) XOR of a number with itself is 0.
b) XOR of a number with 0 is number itself.

int Solution::singleNumber(const vector &A) {
int res=A[0];
for(int i=1;i<A.size();i++)
return res;


what if the input is 1 2 2 2
then res will return 3 and not 1


its not relative to the queston but what changes will u do to handle the above testcase