LC 137. Single Number II

link

每一位1的个数有三种状态,0,1,2,3(0)
用两个bit,low和high来记录这些状态。

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int high=0;
        int low=0;
        for(int n:nums){
            low=(low^n)&(~high);
            high=(high^n)&(~low);
        }
        return low;
    }
};
原文地址:https://www.cnblogs.com/FEIIEF/p/13180480.html