[leedcode 137] Single Number II
1781 ワード
Given an array of integers, every element appears three times except for one. Find that single one.
public class Solution {
public int singleNumber(int[] nums) {
//int 32 bit , bit , mod3, 1 0. ,
int res=0;
for(int i=0;i<32;i++){
int count=0;
for(int j=0;j<nums.length;j++){
count+=(nums[j]>>i)&1;
}
// res+=(count%3)<<i;//
res|=(count%3)<<i;
}
return res;
}
//http://blog.csdn.net/kenden23/article/details/13625297
}