Simple and fast python solution


  • 0
    K
    class Solution(object):
        def countBits(self, num):
            """
            :type num: int
            :rtype: List[int]
            """
            res, loop, full = [0], 0, 0
            while num >= 2 ** loop:
                res += [j + 1 for j in res]
                loop += 1
            return res[:num+1]
    

Log in to reply
 

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