← 返回 apple 的题目列表Count Set Bits in a 32-Bit Integer
类型:online_judge
Given an unsigned 32-bit integer n, return the number of bits set to 1 in its binary representation (the population count).
Requirements:
Do not use a built-in bit-count function.
Target O(k) time, where k is the number of set bits, or provide an O(32) solution.
Example
Input: 11
Output: 3
Explanation: 11 is 00000000000000000000000000001011 in binary.
Constraints: 0 <= n <= 2^32 - 1.
Example
Input
0
Output
0