from sre_compile import CATEGORY_UNI_NOT_LINEBREAK
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param m int整型
# @param n int整型
# @return int整型
#
class Solution:
def countBitDiff(self , m: int, n: int) -> int:
# write code here
m2 = bin(m).replace("0b","")
n2 = bin(n).replace("0b","")
lm=len(m2)
ln=len(n2)
gap=abs(lm-ln)
if len(m2)>len(n2):
n2=gap*"0"+n2
else:
m2=gap*"0"+m2
count=0
for i in range(max(lm,ln)):
if m2[i]!=n2[i]:
count=count+1
return count
#记住需要在位数少的那个数字前面补0 让2个数的长度一样才能进行比较
#尽量用replace函数而不是strip函数