프로그래밍/LeetCode

[LeetCode][Python3] 338. Counting Bits

snoopybox 2019. 9. 24. 01:03

Problem :

https://leetcode.com/problems/counting-bits/


My Solution :

class Solution:
    def countBits(selfnum):
        ans = [0]*(num+1)
        size = 1
        while True:
            for i in range(size):
                try:
                    ans[i+size] = ans[i]+1
                except:
                    return ans
            size *= 2