simple python version


  • 0
    F

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


Log in to reply
 

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