dsa · easy
Number of One Bits
Given a non-negative integer n, return how many 1 bits it has in its binary representation (Hamming weight).
Arguments
n— non-negative integer whose 1-bits you count
Example
n = 11 is 1011 → 3 ones.
Constraints
0 <= n <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 11 Expected: 3
Example 2
Input: 128 Expected: 1