Loading...
Given a positive integer n, return how many bits are set to 1 in its binary representation (its population count, or Hamming weight).
n
1
Input: n = 11 Output: 3 Explanation: 11 in binary is 1011, which has three set bits.
Input: n = 128 Output: 1 Explanation: 128 in binary is 10000000, a single set bit.
Input: n = 2147483645 Output: 30 Explanation: The binary representation 1111111111111111111111111111101 has thirty set bits.
Click "Run" to test with sample cases or "Submit" to run all tests.