Python solution without using bin.count


  • 0
    Z

    def hammingWeight(self, n):
    """
    :type n: int
    :rtype: int
    """
    res = 0
    while n>0:
    if n%2:
    res += 1
    n /= 2
    return res


Log in to reply
 

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