int Solution::numSetBits(unsigned int A) {
int count = 0;
while(A){
A &= (A-1);
count++;
}
return count;
}
The no. of times it runs is same as the number of set bits in number.
int Solution::numSetBits(unsigned int A) {
int count = 0;
while(A){
A &= (A-1);
count++;
}
return count;
}
The no. of times it runs is same as the number of set bits in number.