每次消去末位的1
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int res = 0;
while(n != 0){
n &= n - 1;
res++;
}
return res;
}
}
每次消去末位的1
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int res = 0;
while(n != 0){
n &= n - 1;
res++;
}
return res;
}
}