public int hammingWeight(int n) {
int cnt = 0;
while (n != 0) {
cnt ++;
n = n & (n - 1);
}
return cnt;
}
二进制中1的个数
最新推荐文章于 2024-11-01 14:48:20 发布
public int hammingWeight(int n) {
int cnt = 0;
while (n != 0) {
cnt ++;
n = n & (n - 1);
}
return cnt;
}