1 class Solution { 2 public: 3 int NumberOf1(int n) { 4 int count = 0; 5 while(n){ 6 count++; 7 n = n & (n - 1); 8 } 9 return count; 10 } 11 };