Hamming distance- leetcode

来源:互联网 发布:数组怎么用 编辑:程序博客网 时间:2024/06/01 14:24

开启leetcode刷题模式

今天只做了最简单的 Hamming distance

class Solution(object):    def hammingDistance(self, x, y):        """        :type x: int        :type y: int        :rtype: int               result = bin(x^y).replace('0b','')        result = str(result)        count=0        for  c in result:            if c == '1':                count+=1        return count        """        return bin(x^y).count('1')