/** 137. Single number II * 2016-5-22 by Mingyang * This topic is my idea, you think Ah, each of the numbers are used in binary to indicate, each bit above the sum of 1 of the number should be 3 integer times * If not, then that bit is more 1, so we can use a & to know all the first position on the situation, and then 1 to move to 10, you can also move the * to check the number to the right to move a bit, so that the second bit is moved to the first, and the corresponding array is also counted * so we get an array in the back contains a lot of 1 The number is above, and finally we will restore each of the modules after 3, add to Res*/ Public intSingleNumber1 (int[] A) {if(a.length = = 0| | a==NULL) return0; int[] cnt =New int[32]; for(inti = 0; i < a.length; i++){ for(intj = 0; J < 32; J + +){ if((A[i]>>j & 1) ==1) {Cnt[j]++; } } } intres = 0; for(inti = 0; I < 32; i++) {res+ = (cnt[i]%3 <<i); //Res |= (cnt[i]%3 << i);} CNT=NULL; returnRes; }
137. Single Number II