My attempt with Python code


  • 1
    S
    class Solution(object):
        def countBits(self, num):
            """
            :type num: int
            :rtype: List[int]
            """
            def sum_digits(n):
                s = 0
                while n:
                     s += n % 10
                     n //= 10
                return s
            res =[]
            for i in xrange(0,num+1):
                b = int('{0:08b}'.format(i))
                res.append(sum_digits(b))
            return res

Log in to reply
 

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