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