Bit Manipulation - Counting Bits (0 to N)
The following Python code counts set bits for all numbers from 0 to n by converting each number to a binary string and counting '1's. What is the main inefficiency in this approach?
def countBits(n):
res = []
for i in range(n+1):
res.append(bin(i).count('1'))
return res
