Leetcode 191. 位1的个数

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int ans=0;
        while(n) ++ans,n-=n&-n;
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/bendaai/article/details/81144758