simple ruby solution


  • 0
    T
    def count_bits(num)
        i = 1
        bits = [0]
        while i <= num
            j = 0
            while i + j <= num && j < i*2
                bits[i + j] = 1 + bits[j]
                j += 1
            end
            i *= 2
        end
        return bits
    end
    

Log in to reply
 

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