## Bitwise AND of Numbers Range

### 描述

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.

### 分析

101
110
111


11010
11011
11100
11101
11110


### 解法1

// Bitwise AND of Numbers Range
// Time Complexity: O(log n), Space Complexity: O(1)
public class Solution {
public int rangeBitwiseAnd(int m, int n) {

}
}
}

### 解法2

// Bitwise AND of Numbers Range
// Time Complexity: O(log n), Space Complexity: O(1)
public class Solution {
public int rangeBitwiseAnd(int m, int n) {
while (n > m) {
n &= n - 1;
}
return m & n;
}
}