数组中只有一个数只出现1次,其他的出现3次,找出这个数
public class OnceInOtherThree56 {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 1, 1, 2, 4, 4, 2};
findThat(arr);
}
private static void findThat(int[] arr) {
int[] bit = new int[32];
for (int i = 0; i < arr.length; i++) {
for (int j = 31; j >= 0; j--) {
if ((arr[i] & 1) == 1) {
bit[j] += 1;
}
arr[i] = arr[i] >> 1;
}
}
int temp = 0;
for (int i = 0; i < 32; i++) {
temp = temp << 1;
temp += bit[i]%3;
}
System.out.println(temp);
}
}