FunctionRacerProblemsRace

Number of 1 Bits

EasyBitsPython, JavaScript, TypeScript, Java, C++

Return how many 1 digits appear when the non-negative integer n is written in binary.

Example 1

n 11
returns 3

11 is 1011 in binary, three ones.

Example 2

n 128
returns 1

10000000, one 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems