二进制有多少个1

经典题目

# Number of 1 Bits
# 00000000000000000000000000001011,return 3.
# 2(00000000000000000000000000000010) return 1.

class Solution:
    # @param n, an integer
    # @return an integer
    def hammingWeight(self, n):
        nn=n
        count=0
        while nn:
            count+=1
            nn=nn&(nn-1)
        return count
原文地址:https://www.cnblogs.com/iois/p/4464961.html