461. Hamming Distance

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

这也不是我做出来的…… 想了二十分钟写了各种循环然而放弃了。。果然很简单,异或相同为0相异为1居然tmd半天没想出来。。。


评论

此博客中的热门博文

232. Implement Queue using Stacks

496. Next Greater Element I

20. Valid Parentheses