Sir count bits method discuss is the same or different using n=n&(n-1)

while(n>0)
{
n=n&(n-1)
ans++;
}

@rupeshjha909
there are so many ways to count set bits.
pls refer this ->https://www.geeksforgeeks.org/count-set-bits-in-an-integer/

what is the approach
what about ffs from which c++ version it is introduced

sorry i didnt get what u r asking

i am asing which is the best method i can used

see all are having O(log(n)) time complexity so feel free to use any of them.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like