TWO LINE O(n) C++ without extra memory


#1

int Solution::singleNumber(const vector &A) {

int ones=0,twos=0;

for(int x: A){
    
    ones=(x^ones)&(~twos);  //tracks elements that appear one time
    twos=(x^twos)&(~ones);  // tracks element that appear two times
}
return ones;

}