数组中重复的数字
2023-02-08 本文已影响0人
robertzhai
func findRepeatNumber(nums []int) int {
bitMap := make([]uint64, len(nums)/64+1)
var bit uint64
var slot int
for _,num := range nums {
slot = num / 64
bit = uint64(1)<<(num&63)
if bitMap[slot] & bit != bit {
bitMap[slot] |= bit
} else {
return num
}
}
return 0
}