Hi I have a question on the 12.16 Find an element from array that appears only once(others appear 3 times)
my question is this line in your solution:
next_ones = (~i & ones) | (i & ~ones & ~twos);
I know this line is matching your explanation part “…the count was 0 modulo 3 and the j-th bit in Ai-1 is a one”.
However, I think, to match your explanation the code should be
next_ones = (~i & ones) | (i & ~ones & ~twos) | (i & ones & twos);
But to my astonishment, I found that even if you don’t add " |(i & ones & twos)", your code passes all the test cases and no bugs.
My question is
Why does next_ones = (~i & ones) | (i & ~ones & ~twos) suffice?
Thanks