137.Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = 0;
for(int i = 0; i < 32; i++){
int bitSum = 0;
int bit = 1<<i;
for(int j = 0; j < nums.size(); j++){
if(nums[j]&bit){
bitSum++;
}
}
if(bitSum % 3 ) res |= bit;
}
return res;
}
};