Very simple 5 line python solution beats 92%

  • 0

    class Solution(object):
    def hammingWeight(self, n):
    :type n: int
    :rtype: int
    nb = "{0:b}".format(n)
    c = 0
    for i in range(len(nb)):
    if nb[i] == '1':
    return c

Log in to reply

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