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

posted @ 2018-05-03 21:34  kkkkkksssss  阅读(108)  评论(0编辑  收藏  举报