Problem
Given a positive integern, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight).
Examples
Constraints
- 1 <= n <= 2^31 - 1
Tested Python solution for LeetCode 191 with 16 pytest cases. Generate a practice environment with lcpy.
n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight).