题目:
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?
分析:
数电里面学过这部分的知识,无奈我都忘得差不多了。画状态转换图画了好久也没对。我对不起我数电老师。
代码:
class Solution {
public:
int singleNumber(vector<int>& nums) {
int high=0,low=0;
int size=nums.size();
for(int i=0;i<size;++i){
high=(high^nums[i])&~low;
low=(low^nums[i])&~high;
}
return high;
}
};