```
class Solution(object):
def countBits(self, num):
"""
:type num: int
:rtype: List[int]
"""
power = 0;
result = [];
result.append(0);
#result.append(1);
while len(result)<=num:
for x in xrange(2**power):
result.append(result[x]+1);
if len(result)>num:
break;
power += 1;
return result
```