2/100. Hamming Distance

class Solution:
    def hammingDistance(self, x, y):
        """
        :type x: int
        :type y: int
        :rtype: int
        """
        return(bin(x^y).count('1'))
                
  • Python位运算符:^

    当两对应的二进位相异时,结果为1

  • 十进制转二进制:bin()

相关文章:

  • 2022-12-23
  • 2021-05-14
  • 2021-06-05
  • 2021-09-05
  • 2022-02-27
  • 2021-08-09
猜你喜欢
  • 2021-04-05
  • 2021-06-23
  • 2021-12-20
相关资源
相似解决方案