Number of 1 Bits
EasyP2Coding
Given a non-negative integer n (treated as an unsigned 32-bit value), return the number of 1 bits in its binary representation.
Example 1
- Input
- n = 11
- Output
- 3
- Why
- 11 is 1011 in binary, which has three 1 bits.
Example 2
- Input
- n = 128
- Output
- 1
Example 3
- Input
- n = 0
- Output
- 0
Constraints
- 0 <= n <= 2^32 - 1
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.