1 public class Solution { 2 public int singleNumber(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int len = A.length; 6 if(A == null) 7 return 0; 8 9 int[] result = new int[32]; 10 int finalresult = 0; 11 for(int i = 0; i < 32; i++){ 12 for(int j = 0; j < len; j++){ 13 if(((A[j] >> i) & 1) == 1) 14 result[i] = (result[i] + 1) % 3; 15 } 16 finalresult |= (result[i] << i); 17 } 18 return finalresult; 19 } 20 }
every element appears n times except for one