Simple Python Solution


  • 0
    B
    import math
    class Solution(object):
        def countBits(self, num):
            lists = [0]
            if num != 0: index1 = (int)(math.log(num,2))
            else: return lists
            index2 = (int)(num%(math.pow(2,index1)))
            for i in range(index1):
                lists = lists + [x+1 for x in lists]
            lists = lists + [x+1 for x in lists[:index2+1]]
            return lists

Log in to reply
 

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