Incredible hulk problem


sample test case is passed, but it is showing wrong answer

you need to count no of set bits present in the number.
since assume that n = 101110011 in binary form, then hulk needs 6 jumps only(as there are 6 1’s). think about it.
the solution is:
int incredibleHulk(int n) {

int count = 0;

// int temp = n;
while (n) {
count++;
n = n&(n-1);
}

// int k = 1 << (count - 1);
// return 1 + (n - k);
return count;

}

note: n&(n-1) unset the first set bit from LSB.

thanks