剑指OFFER----面试题15. 二进制中1的个数

链接:https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/submissions/

代码:

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

猜你喜欢

转载自www.cnblogs.com/clown9804/p/12337391.html