class Solution:
def countBits(self, num):
"""
:type num: int
:rtype: List[int]
"""
# 一次遍历
# return [bin(i)[2:].count('1') for i in range(num+1)]
# method two 更加高效的解法,少调用内置函数,挖掘数据中的规律
ans = [0]
while len(ans) < num + 1:
ans += [1 + x for x in ans]
return ans[:num+1]