C++ 直接与上n-1,直到为0。
class Solution { public: int NumberOf1(int n) { int max = 0; while(n){ n &= n-1; max++; } return max; } };