Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
扩展2进制亦或的定义到三进制
class Solution {
public int singleNumber(int[] nums) {
int result = 0;
for(int i = 0 ;i<32;i++)
{
int mask=1<<i;
int count=0;
for(int j = 0 ;j<nums.length;j++)
{
int val = nums[j]&mask;
if(val==mask)
count++;
}
count=(count%3)<<i;
result=count|result;
}
return result;
}
}