Simplest XOR implementation


#1

Since XOR of same numbers is zero, if we XOR every element, the equal elements will cancel out and unique element will be left

int Solution::singleNumber(const vector<int> &A) {
    int ans = 0;
    for(int i=0;i<A.size();i++){
        ans = ans ^ A[i];
    }
    return ans;
}