solve(nums) — every value of nums (non-negative, < 2^31) appears three times
except one, which appears once. Return the single one in O(n) time and O(1) space.
XOR no longer cancels triples. Think per bit: for any bit position, the number of
values having that bit set is a multiple of 3, plus 1 if the single value has it. So count
the ones in each of the 31 positions modulo 3 and rebuild the answer from the leftover bits.
(A neat constant-time-per-value version keeps two integers, ones and twos, that
together form a modulo-3 counter for all bits at once.)
Examples
solve([2,2,3,2]) → 3
solve([0,1,0,1,0,1,99]) → 99
solve([5]) → 5Sample tests