Python solution


  • 0
    R
    class Solution(object):
     def countBits(self, num):
        res, exp = [], 4
        for i in xrange(num+1):
            if i == 0 or i == 1:
                res.append(i)
            else:
                exp = exp if i < exp else exp << 1
                res.append(res[i-exp/2] + 1)
        return res

Log in to reply
 

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