```
class Solution {
public:
int singleNumber(vector<int>& nums) {
int ret = 0, i = 0, j = 0;
int n = nums.size(), intlen = sizeof(int) * 8;
vector<int> cnt(intlen, 0);
for (i = 0; i < n; ++i)
{
for (j = 0; j <intlen; ++j)
{
cnt[j] += ((nums[i] >> j) & 1);
cnt[j] %= 3;
}
}
for (i = 0; i < intlen; ++i)
ret += (cnt[i] << i);
return ret;
}
};
```