Leetcode 338 Solution
This article provides solution to leetcode question 338 (counting-bits)
Access this page by simply typing in "lcs 338" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/counting-bits
Solution
class Solution {
public:
vector<int> countBits(int num) {
vector<int> res(num + 1);
res[0] = 0;
for (int i = 1; i <= num; i++)
res[i] = res[i & (i - 1)] + 1;
return res;
}
};