CodeOath
← All problems

Number of 1 Bits

Easy
bit-manipulation

Given a non-negative integer n, return the number of set bits (1s) in its binary representation (the Hamming weight).

Example:

Input: n = 11
Output: 3
Explanation: 11 is 1011 in binary, which has three 1 bits.

Constraints:

  • 0 <= n <= 2^31 - 1