# LeetCode338 Counting Bits

## 描述

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.

• It is very easy to come up with a solution with run time O(n*sizeof(integer)). But can you do it in linear time O(n) /possibly in a single pass?
• Space complexity should be O(n).
• Can you do it like a boss? Do it without using any builtin function like __builtin_popcount in c++ or in any other language.

## 思路

$0$~$n$$n+1$个数，每个数的二进制表示中1的个数是多少。

• 直接遍历每个二进制位：
• 有多少个1就遍历多少次（通过lowbit跳转）：