Simple python method


  • 0
    Z

    def countBits(self, num):

    res=[0]*(num+1)
    i=1;flag=1
    while i<=num:
        if i>=(1<<flag):
            flag+=1
        res[i]=1+res[(~(1<<(flag-1)))&i]
        i=i+1
    return res

Log in to reply
 

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