← Back to problems Solve on LeetCode →

Number of 1 Bits

LeetCode 191 • Easy • Bit manipulation

Return the number of 1 bits (Hamming weight) of unsigned 32-bit n. Example: n = 11 (binary 1011) → 3.

TimeO(32)
SpaceO(1)
Step0/0
Ready
While n is non-zero: add n & 1 to count, then n >>= 1.