直接用$bitset$做,复杂度几乎为$O(1)$
#include <bitset> class Solution { public: int NumberOf1(int n) { bitset <32> b(n); return b.count(); } };