public class Solution {
public static int hammingWeight(int n) {
int c = 0;
while(n != 0) {
n = n & (n - 1);
c++;
}
return c;
}
public static int hammingWeight1(int n) {
int c = n < 0 ? 1 : 0,d = 1;
while(d > 0) {
if((n & d) == d) c++;
d = d<<1;
}
return c;
}
}
leetcode位1的个数
最新推荐文章于 2024-06-06 19:17:22 发布