Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> countBits(int num) {
- vector<int>ans;
- int x=1;
- int pow = 1; //2*m+x
- ans.push_back(0);
- for(int i=1;i<=num;i++)
- {
- if(i==pow)
- {
- ans.push_back(1);
- x = 1;
- pow=pow<<1;
- }
- else
- {
- ans.push_back(ans[x]+1);
- x++;
- }
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment