class Solution:
    def countBits(self, n):
        res = []
        for i in range(n + 1):
            # format(i, 'b') --> convert an integer to a binary string without prefix
            res.append(format(i, 'b').count('1'))
        return res 
[220301] Counting Bits
阅读 127
2022-03-11
class Solution:
    def countBits(self, n):
        res = []
        for i in range(n + 1):
            # format(i, 'b') --> convert an integer to a binary string without prefix
            res.append(format(i, 'b').count('1'))
        return res 
相关推荐
精彩评论(0)