C++ Solution XOR (4 Line)


#1
int ans = 0;
for(int i=0;i<A.size();i++)
    ans = ans^A[i];
return ans;

#2

what when input is 1,2,2,2 output will be 3 not 1 ?


#3

it’s ok, but if inpur is (1,2,2,2) then output will not be 1 …


#4

Read the question the again, “every element appears twice except for one”. So there can’t be three instances of any number.