Python solution beats 100%


  • 0
    X

    i was inspired by the hint

    class Solution(object):
        def countBits(self, num):
            """
            :type num: int
            :rtype: List[int]
            """
            a=[0]
            window = 1
            i=1
            count =0
            while(i<=num):
                if(count==window-1):
                    window=window*2
                    count=0
                a.append(1+a[i-window])
                
                count+=1
                i+=1
        return a

Log in to reply
 

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