我的算法之路20--位1的个数

class Solution(object):
    def hammingWeight(self, n):
        """
        :type n: int
        :rtype: int
        """
        cont=0
        while(n>0):
            cont+=1
            n=(n-1)&n
        return cont

猜你喜欢

转载自blog.csdn.net/joaming/article/details/89478398