Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created June 6, 2018 14:20
Show Gist options
  • Save s4553711/95efb7b2eee489a889cce17f58f647fc to your computer and use it in GitHub Desktop.
Save s4553711/95efb7b2eee489a889cce17f58f647fc to your computer and use it in GitHub Desktop.
class Solution {
public:
vector<int> countBits(int num) {
vector<int> res = vector<int>(num+1, 0);
for(int i = 1; i <= num; i++) {
res[i] = res[i >> 1] + (i & 1);
}
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment