461.汉明距离(通过)Python

class Solution:
    def hammingDistance(self, x, y):
        """
        :type x: int
        :type y: int
        :rtype: int
        """
        count = 0
        while True:
            if x == 0 and y == 0:
                break
            x, x_mod = divmod(x, 2)
            y, y_mod = divmod(y, 2)
            if x_mod != y_mod:
                count += 1
        return count

你可能感兴趣的:(Python,Leecode)