public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int hw = 0, shiftCount = 0;
while (shiftCount++ < 32) {
hw += (n & 1);
n = n >> 1;
}
return hw;
}
}
LeetCode 191. Number of 1 Bits
最新推荐文章于 2023-12-19 11:17:46 发布