题解 | #数组中只出现一次的数(其它数出现k次)#
数组中只出现一次的数(其它数出现k次)
http://www.nowcoder.com/practice/5d3d74c3bf7f4e368e03096bb8857871
package main
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param arr int一维数组
* @param k int
* @return int
*/
func foundOnceNumber( arr []int , k int ) int {
// write code here
if len(arr) == 0{
return 0
}
res := 0
for i:=0; i<64; i++{
count := 0
for j:=0; j<len(arr); j++{
if arr[j] & (1<< i) > 0 {
count++
}
}
count = count%k
res |= (count << i)
}
return res
}
查看20道真题和解析
传音控股公司福利 333人发布