题目:
解答:
1 class Solution { 2 public: 3 int hammingWeight(uint32_t n) 4 { 5 int res = 0; 6 while(n != 0) 7 { 8 res += n & 1; 9 n >>= 1; 10 } 11 return res; 12 } 13 };
面试题15. 二进制中1的个数
原文:https://www.cnblogs.com/ocpc/p/12857022.html