leetcode-python-汉明距离


	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
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » leetcode-python-汉明距离