@nju_yaho Among all the answer, I love yours the best. Use 2 bits for 4 states, 3 bits for 5 and 6 states needs a lot of work to figure out the formula and not as intuitive.

@zws1818918
Well, here's what I understand...
We should use binary to construct triad, that's also why we only use a and b instead of an 32-length array of int to record every bit's counter.
We know that a and b have four states: 00 01 10 11, but we only use 00 01 10 three states (11 is not exist because we count 3 times, when 11 show it should be 00). From these three states and different c(maybe 0 or 1) we get a table with 6 rows like the author gave us. And also like original method we count a number,
00 + 1 = 01, 01 + 1 = 10 but 10 + 1 = 00 (we construct triad so 11 is not exist, it should be original state)
Obviously, everything add 0 is itself...
So that's why we come up with the truth table.

we use state (0,0) (0,1) (1,1) to represent we've met bit 1 for 0,1,2 times.
So if the incoming bit is 0, state keeps unchanged while for 1 we come to the next one.
It's brilliant!

I think the last 6 line should be changed to if(digits[i]%3>0). Otherwise, there will be not covered the case that the exceptional number appears in TWICE, such as {1,3,4,1,3,4,5,5,1,3,4}

Thanks for the answer. Although this is not the optimal one (it takes O(32n) complexity because of the outer loop), but it is easy to understand and it is more likely to be the solution that one can quickly come up during an interview.