剑指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;
}
};