191. Number of 1 Bits
Practice Number of 1 Bits for free on NudgeCode: Easy, Bit Manipulation pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Return the number of 1 bits in the binary representation of positive integer n.
Example
n = 11 -> 3 (1011)
n = 128 -> 1 (10000000)
Current public problem constraints
- 1 <= n <= 2^31 - 1
Local practice extension
The local helper and tests also accept 0 and return 0 for it. This natural extension is retained for teaching; the current public LC191 contract does not require zero input.