# Challenge me , thx

• @XiaoweiLu actually the ones represents all bits of number,the same as twos

• @ofLucas Thanks very much for your detailed explanation. I finally see what's going on here.

• Four multiple states situation it would be much easier to use `n` bits to represent at most `n-1` appearing times, it requires more space but avoiding headache.

• @againest1 a two-counter in reality which is circular

• @LoveTTn

This is what I think:

• VAR ^ 4,
if there is no 4 in VAR, means SAVE 4 into VAR.
if there is 4 in VAR, means CLEAR 4 from VAR.
• 7 & (~4) = 3, means CLEAR 4 from 7.

• VAR & (-4), means CLEAR 4 form VAR.

For example, an array {1, 2, 2, 1, 1, 7, 2 }

``````        1        2       2       1         1       7     2
one  [1]     [1,2]    [1]    [null]    [null]   [7]   [7] (<=Answer)
two  [null]  [null]   [2]    [1,2]     [2]      [2]   [0]

Index form 0 to 6.....====>>>>>>
``````

※ which [N] means the info in variables.

• @lgzvalle Thank you for your explanation.

• U can easily prove this by using the Karnaugh map.

• @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.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.