LeetCode 191 Number of 1 Bits - Problem Statement

The problem

Count the number of 1 bits (set bits) in a 32-bit unsigned integer. This is also called the Hamming weight.

With n = 00000000000000000000000000001011 (binary):

  • 1 bits at positions 0, 1, and 3.
  • Answer: 33.

With n = 11111111111111111111111111111101:

  • 31 bits are set to 1.
  • Answer: 3131.

Constraints: Input is a 32-bit unsigned integer.