首页 > 编程语言 > 详细

leetcode-python-汉明距离

时间:2021-06-11 16:53:37      阅读:29      评论:0      收藏:0      [点我收藏+]

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

 

leetcode-python-汉明距离

原文:https://www.cnblogs.com/cbachen/p/14875071.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!