461. Hamming Distance

题目地址:https://leetcode.com/problems/hamming-distance/description/
大意:求两个int型整数的汉明距离(Hamming Distance)

比较简单,两个二进制数的疑惑然后求1的个数。

# 461. Hamming Distance
class Solution:
    def hammingDistance(self, x, y):
        """
        :type x: int
        :type y: int
        :rtype: int
        """
        return bin(x^y).count('1')


a = Solution()
print (a.hammingDistance(1,4))

所有题目解题方法和答案代码地址:https://github.com/fredfeng0326/LeetCode
    原文作者:fred_33c7
    原文地址: https://www.jianshu.com/p/916fe20a13e1
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞