338. Counting Bits

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

你可能感兴趣的:(338. Counting Bits)