2018-11-28 leetcode Counting Bits Counting BitsBitwise Operator Version - 108ms 12345678910class Solution: def countBits(self, num): """ :type num: int :rtype: List[int] """ res = [0] for i in range(1, num + 1): res.append(res[i >> 1] + (i & 1)) return res test code 12In [147]: s = Solution(); t = s.countBits(5); print(t)[0, 1, 1, 2, 1, 2] leet code Newer Queue Reconstruction by Height Older Merge Two Binary Trees