338. Counting Bits——dp

338. Counting Bits——dp

0-num中每个二进制数中1的个数

class Solution(object):
    def countBits(self, num):
        """
        :type num: int
        :rtype: List[int]
        """
        dp = [0]
        for i in range(1, num + 1):
        
            dp.append(dp[i & (i-1)] + 1)
        return dp