Count Set Bits

Given a non-negative integer n, return how many 1s its binary representation has. For example, 11 is 1011 in binary, which has three 1s.

Constraints

  • 0 ≤ n ≤ 2,147,483,647

Example 1

Input
n = 11
Output
3
Why:

11 is 1011.

Example 2

Input
n = 128
Output
1
Why:

128 is 10000000.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –