Skip to content

Commit 4bbda72

Browse files
committed
Time: 11 ms (7.93%), Space: 7.9 MB (100%) - LeetHub
1 parent e286518 commit 4bbda72

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
vector<int> countBits(int n) {
4+
vector<int> ans(n + 1);
5+
for (int i = 0; i <= n; i++)
6+
{
7+
int temp = i;
8+
for (int j = 0; j < 32; j++)
9+
{
10+
if(temp & 1)
11+
ans[i]++;
12+
temp >>= 1;
13+
}
14+
}
15+
return ans;
16+
}
17+
};

0 commit comments

Comments
 (0)