【LeetCode】137. 只出现一次的数字 II
class Solution { public: int singleNumber(vector<int>& nums) { int ans = 0; int total = 0; for(int i = 0; i<32 ; ++i) { total = 0; for(int j=0; j<nums.size(); ++j) { total+=(nums[j]>>i)&1; //按位统计某一位的数能否被3整除 } if(total%3) //不能整除,则答案出现在这一位上 ans|=(1<<i); } return ans; } };

浙公网安备 33010602011771号