面试经典150题 P191 位1的个数
时间轴
2025-11-25
init
题目:
可以直接使用内置函数__builtin_popcount1
2
3
4
5
6
7class Solution {
public:
int hammingWeight(int n)
{
return __builtin_popcount(n);
}
};
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 常想一二,不思八九!
评论
时间轴
2025-11-25
init
题目:
可以直接使用内置函数__builtin_popcount1
2
3
4
5
6
7class Solution {
public:
int hammingWeight(int n)
{
return __builtin_popcount(n);
}
};