Skip to content

Commit bbc9da3

Browse files
committed
Counting Bits solution
1 parent 865aa45 commit bbc9da3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

counting-bits/PDKhan.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
vector<int> countBits(int n) {
4+
vector<int> result(n + 1, 0);
5+
6+
for(int i = 0; i <= n; i++){
7+
result[i] = result[i >> 1] + (i & 1);
8+
}
9+
10+
return result;
11+
}
12+
};

0 commit comments

Comments
 (0)