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