Skip to content

Commit a083084

Browse files
committed
add cpp solution
1 parent 8807eca commit a083084

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> countBits(int num) {
4+
vector<int> ans(num+1, 0);
5+
int m = 1;
6+
for (int i = 1; i <= num; i++){
7+
if (i == m){
8+
ans[i] = 1;
9+
m <<= 1;
10+
}
11+
else ans[i] = ans[i - m/2] + 1;
12+
}
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)