066_汉明距离

知识点:位运算

LeetCode第四百六十一题:https://leetcode-cn.com/problems/hamming-distance/

语言:GoLang

func hammingDistance(x int, y int) int {
    x = x ^ y

    count := 0
    for x > 0 {
        x = x & (x - 1)
        count++
    }
    return count
}
posted @ 2020-07-16 13:22  Cenyol  阅读(74)  评论(0编辑  收藏  举报