leetcode-python-汉明距离

1)取异或,然后计算1的个数

class Solution:
    def hammingDistance(self, x: int, y: int) -> int:
        t = x^y
        count = 0
        while t:
            count += 1
            t = t& t-1
        return count

 

posted @ 2021-06-11 14:50  泊鸽  阅读(44)  评论(0)    收藏  举报