题目
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.
Example 1:
1 | Input: [5,7] |
Example 2:
1 | Input: [0,1] |
思路
数学题。
[m, n]范围的按位与的结果即为m与n的公共左边首部,所以将m和n右移到公共部分再左移还原即可。
代码
1 | class Solution(object): |