XOR without bitmask


#1
int Solution::singleNumber(const vector<int> &A) {
    int first = 0;
    int second = 0;
    for(auto n:A){
        first = (first ^ n) & ~second;
        second = (second ^ n) & ~first;
    }
    return first;
}

#2

Can you please explain what you are doing here?


#3

Please explain your code, I have searched on youtube somebody else has also solved like this but I am not able to understand, if you could explain it would be a great help.
Thanks.


#4

Here, He counts no. of set bit at ith position for whole array,by taking %3 we get the bit which does not repeat(rest come 3 times).