Skip to main content
easyBlind 75

Number of 1 Bits

Count the number of 1 bits in the binary representation Example: 11 (binary: 1011) => 3

The trick is `n &= n - 1`, which clears the lowest set bit. I loop once per one-bit instead of walking all thirty-two.

Bit Manipulation

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Number of 1 Bitseasy
Based onLeetCode