美文网首页
数组中重复的数字

数组中重复的数字

作者: robertzhai | 来源:发表于2023-02-08 08:06 被阅读0次
    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
    
    }
    

    相关文章

      网友评论

          本文标题:数组中重复的数字

          本文链接:https://www.haomeiwen.com/subject/ptifkdtx.html