Single Number II


Given an array of integers, every element appears three

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

class Solution {
public:
//出现3次,每位都3次,对3取余为0,,剩余的就是那个单独的数
int singleNumber(vector<int>& nums) {

int one=0,two=0,three=0;
for(int i=0;i<nums.size();i++)
{
two|=one&nums[i];
one^=nums[i];
three=(one&two);
one&= ~three;//三次清0
two&= ~three;
}
return one;
}
};