顿搜
飞过闲红千叶,夕岸在哪
类目归类
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.
For example, given the range [5, 7], you should return 4.
Input: 5, 7
Ouput: 4
public int rangeBitwiseAnd(int m, int n) {
while (n > m) {
n &= n & (n - 1);
}
return n & m;
}public class LeetCode0201 {
public int rangeBitwiseAnd(int m, int n) {
while (n > m) {
n &= n & (n - 1);
}
return n & m;
}
public static void main(String[] args) {
LeetCode0201 leetcode = new LeetCode0201();
System.out.println(leetcode.rangeBitwiseAnd(0, 2147483647));
}
}