one line python solution by xor

  • 0

    class Solution:
    def hammingDistance(self, x, y):
    return bin(x^y).count('1')
    Use the xor to determine the different bits, and use"str.count('1')" to count the number of different bits.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.