461. Hamming Distance
https://leetcode.com/problems/hamming-distance
Python
class Solution:
def hammingDistance(self, x: int, y: int) -> int:
bin_x = "{0:b}".format(x)
bin_y = "{0:b}".format(y)
len_x = len(bin_x)
len_y = len(bin_y)
max_len = max(len_x, len_y)
bin_x = bin_x.zfill(max_len)
bin_y = bin_y.zfill(max_len)
counter = 0
for i in range(0, max_len):
if int(bin_x[i]) ^ int(bin_y[i]) == 1:
counter += 1
return counter