递归方法:f[n] = f[n/2] + f[n%2]
class Solution(object):
def countBits(self, num):
"""
:type num: int
:rtype: List[int]
"""
dp = [0,1,1]
if num <= 2:
return dp[:num+1]
for i in range(3, num + 1):
dp.append(dp[i//2] + i%2)
return dp