Given an array of integers, every element appears twice except for one. Find that single one.
第一种解法就是《剑指offer》上的,下面是一种通用的解法:
public class Solution {
public static int singleNumber(int[] nums) {
int[] count=new int[32];
int result=0;
for(int i=0;i<32;i++){
for(int j=0;j<nums.length;j++){
count[i]+=(nums[j]>>>i)&1;
}
count[i]=count[i]%2;
result|=(count[i]<<i);
}
return result;
}
}