剑指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;
    }
};

 

posted @ 2020-02-20 20:48  景云ⁿ  阅读(96)  评论(0)    收藏  举报