题解 | #数组中只出现一次的数(其它数出现k次)#
数组中只出现一次的数(其它数出现k次)
http://www.nowcoder.com/practice/5d3d74c3bf7f4e368e03096bb8857871
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param arr int一维数组
* @param k int
* @return int
*/
public int foundOnceNumber (int[] arr, int k) {
// write code here
int[] count = new int[32];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < 32; j++) {
count[j] = count[j] + (arr[i] & 1);
arr[i] >>>= 1;
}
}
int res = 0;
for (int i = 0; i < 32; i++) {
res <<=1;
res |= count[31 - i] % k;
}
return res;
}
}