201. 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.

201. Bitwise AND of Numbers Range_第1张图片

[26, 30],它们的二进制如下:
左边公共部分决定了区间与的结果, 所以找到它再向左移回来。

你可能感兴趣的:(201. Bitwise AND of Numbers Range)