ones记录只出现过一次的bits,twos记录出现过两次的bits,threes记录出现过三次的bits;
仔细理解还是很好理解的,具体看代码:
class Solution {
public:
int singleNumber(int A[], int n) {
int ones=0,twos=0,threes;
for(int i=0;i<n;i++){
int t=A[i];
twos|=ones&t;
ones^=t;
threes=ones&twos;
ones&=~threes;
twos&=~threes;
}
return ones;
}
};