ones
and twos
to 0. These variables will hold the bits that have appeared once and twice respectively.nums
.
a. Update ones
with the current number using XOR to add bits that are appearing for the first time and remove bits that are appearing for the second time.
b. Update twos
with the current number using XOR to add bits that are appearing for the second time and remove bits that are appearing for the third time.
c. Use a mask to clear bits that have appeared three times from both ones
and twos
.ones
, which now contains the bits of the unique number.