思路
方法:位运算
遍历统计
1 class Solution { 2 private: 3 int cnt[32] = {0}; 4 public: 5 int singleNumber(vector<int>& nums) { 6 for(int num: nums) { 7 for(int i = 0; i < 32; ++i) { 8 cnt[i] += (num & 1); 9 num >>= 1; 10 } 11 } 12 13 int res = 0; 14 for(int i = 31; i >= 0; --i) { 15 res <<= 1; 16 res |= (cnt[i] % 3); 17 } 18 19 return res; 20 } 21 };