其他分享
首页 > 其他分享> > LeetCode 191. 位1的个数 Number of 1 Bits

LeetCode 191. 位1的个数 Number of 1 Bits

作者:互联网

 

 

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int res = 0;
        int i = 32;
        while (i--)
        {
            res += n & 1;
            n >>= 1;
        }
        return res;
    }
};

 

标签:return,int,res,191,Solution,hammingWeight,Bits,LeetCode
来源: https://www.cnblogs.com/ZSY-blog/p/12977208.html