每次消去末位的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;
}
}
暂无评论
2023-12-22
2023-12-08
2023-12-06
2023-12-05
2023-11-13
2023-11-02
2023-11-02
2023-11-02
2023-11-02
2023-11-02
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31
2024-05-31