leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0338.cpp (286B)


0 class Solution {
1 public:
2 vector<int> countBits(int n) {
3 vector<int> res(n + 1);
4 int offset = 1;
5 for (int i = 1; i <= n; i++) {
6 if (offset * 2 == i) offset *= 2;
7 res[i] = (res[i - offset]) + 1;
8 }
9 return res;
10 }
11 };