Log in to run or submit
Brian Kernighan’s trick: n & (n-1) clears the lowest set bit.
n & (n-1)
Loop while n != 0, clear one bit each iteration and count.
n != 0