链接:LeetCode201
过程:想了想,看题解,求前缀用位移和Brian Kernighan算法
思路:略
代码:
class Solution {
public int rangeBitwiseAnd(int m, int n) {
int cnt=0;
while(m<n){
n=n&(n-1);
}
return n;
}
}
本文详细解析了LeetCode201题的解决方案,通过使用位移和Brian Kernighan算法来求解前缀问题,提供了一种高效且直观的方法。
链接:LeetCode201
过程:想了想,看题解,求前缀用位移和Brian Kernighan算法
思路:略
代码:
class Solution {
public int rangeBitwiseAnd(int m, int n) {
int cnt=0;
while(m<n){
n=n&(n-1);
}
return n;
}
}
415
875
181

被折叠的 条评论
为什么被折叠?