0191.cpp (166B)
1 class Solution { 2 public: 3 int hammingWeight(uint32_t n) { 4 int res = 0; 5 while (n) 6 res += n & 1, n >>= 1; 7 return res; 8 } 9 };