剑指OFFER----面试题56 - II. 数组中数字出现的次数 II

链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/

代码

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int ones = 0, twos = 0;
        for (auto x: nums) {
            ones = (ones ^ x) & ~twos;
            twos = (twos ^ x) & ~ones;
        }
        return ones;
    }
};
posted @ 2020-03-11 14:24  景云ⁿ  阅读(69)  评论(0编辑  收藏  举报