We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db1cdba commit 68151ceCopy full SHA for 68151ce
28 - Counting Bits.cpp
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ int count_one(int n){
4
+ int res = 0;
5
+ if(n == 0){
6
+ return 0;
7
+ }
8
+ while(n > 0){
9
+ if(n%2 == 1){
10
+ res++;
11
12
+ n = n/2;
13
14
+ return res;
15
16
+
17
18
+ vector<int> countBits(int num) {
19
+ vector<int> result;
20
+ for(int i = 0; i<=num; i++){
21
+ result.push_back(count_one(i));
22
23
+ return result;
24
25
+};
0 commit comments