编程之美 [leetcode_191]Number of 1 Bits 请输入整数的二进制中1的个数,简单的模拟。 1 2 3 4 5 6 7 8 9 10 11 12 class Solution { public: int hammingWeight(uint32_t n) { int count = 0; while(n > 0) { count += n%2; n /= 2; } return count; } };