Given an array of integers, every element appears three times except for one. Find that single one.
1 public class Solution { 2 public int singleNumber(int[] A) { 3 int bit [] = new int[32]; 4 for(int i=0;i<A.length;i++){ 5 for(int j=0;j<32;j++){ 6 int rotate = A[i]>>j; 7 if(rotate==0) break; 8 else bit[j] += rotate&1; 9 } 10 11 } 12 int sum = 0; 13 for(int i=0;i<32;i++){ 14 sum += bit[i]%3<<i; 15 } 16 return sum; 17 } 18 }
原文:http://www.cnblogs.com/krunning/p/3560678.html