Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory
1:采用xor
int singleNumber(int A[], int n)
{
int once = 0;
int twice = 0;
int third = 0;
for(int i = 0; i < n; i++)
{
twice |= once & A[i];
once ^= A[i];
third = once & twice;
once &= ~third;
twice &= ~third;
}
return once;
}