https://leetcode.com/problems/hamming-distance/
class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
string = bin(x^y)
res = 0
for i in string:
if i == '1':
res +=1
return res
本文介绍了一个计算两个整数之间汉明距离的方法。通过将两个整数进行异或运算并转换为二进制字符串,然后遍历该字符串计数其中的'1'的数量,从而得到两个整数的汉明距离。
401

被折叠的 条评论
为什么被折叠?



