PS: integer not converted to binary form, the required number of binary integer form 1 of
#include <iostream>
class Count_1_num {
public:
int count(int n) {
int res = 0;
while (n) {
n = n & (n - 1);
res++;
}
return res;
}
};
PS: integer not converted to binary form, the required number of binary integer form 1 of
#include <iostream>
class Count_1_num {
public:
int count(int n) {
int res = 0;
while (n) {
n = n & (n - 1);
res++;
}
return res;
}
};