leetcode-----137. 只出现一次的数字 II

代码

/*
 * @lc app=leetcode.cn id=137 lang=cpp
 *
 * [137] 只出现一次的数字 II
 */

// @lc code=start
class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int one = 0, two = 0;
        for (auto x: nums) {
            one = (one ^ x) & ~two;
            two = (two ^ x) & ~one;
        }
        return one;
    }
};
// @lc code=end
posted @ 2020-08-01 17:12  景云ⁿ  阅读(119)  评论(0编辑  收藏  举报