Given a positive integer n, determine how many bits with value 1 appear in its binary representation. This quantity is often called the population count or Hamming weight.
Example 1
Input: n = 13
Output: 3
Explanation: The binary form of 13 is 1101, which contains three 1‑bits.
Example 2
Input: n = 64
Output: 1
Explanation: 64 in binary is 1000000; it contains exactly one 1‑bit.
Example 3
Input: n = 2147483645
Output: 30
Explanation: The binary representation is 31 bits long, and all bits except the second‑least significant are set to 1.
1 <= n <= 2^31 - 1If this function will be called many times on different inputs, how could you make each invocation cheaper than solving from scratch?