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

相关文章:

  • 2021-04-24
  • 2021-12-09
  • 2021-09-23
  • 2021-05-30
  • 2021-10-21
  • 2022-12-23
  • 2022-02-09
猜你喜欢
  • 2021-07-12
  • 2021-11-30
相关资源
相似解决方案