LeetCode461.汉明距离

class Solution:
    def hammingDistance(self, x, y):
        """
        :type x: int
        :type y: int
        :rtype: int
        """
        binaryX = "{:0>32}".format(bin(x)[2:])
        binaryY = "{:0>32}".format(bin(y)[2:])

        index = 0
        count = 0
        for strX in str(binaryX):
            if strX != binaryY[index]:
                count += 1
            index += 1
        return count

原文地址:https://www.cnblogs.com/ldgforever/p/9839805.html