剑指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 @   景云ⁿ  阅读(69)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示