class Solution {
public:
int hammingWeight(uint32_t n) {
int cnt = 0;
for(uint32_t bit = 1; bit; bit <<= 1) if(n & bit) cnt++;
return cnt;
}
};
【leetcode 位运算 C++】191. Number of 1 Bits
猜你喜欢
转载自blog.csdn.net/m0_37454852/article/details/113936261
今日推荐
周排行