class Solution { public: int NumberOf1(int n) { int cnt = 0; for(int i = 0; i < 31; ++i) if(n >> i & 1) ++cnt; cnt += n < 0 ? 1 : 0; return cnt; } };