class Solution(object): def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int """ x_bin = list(bin(x)) y_bin = list(bin(y)) x_bin.reverse() y_bin.reverse() x_judge = [] y_judge = [] for x in x_bin: if x == 'b': break x_judge.append(x) for y in y_bin: if y == 'b': break y_judge.append(y) list_distance = abs(len(x_judge) - len(y_judge)) if len(x_judge) < len(y_judge): for i in range(list_distance): x_judge.append('0') else: for i in range(list_distance): y_judge.append('0') distance = 0 for i in range(len(x_judge)): if x_judge[i] != y_judge[i]: distance += 1 return distance