一. 题目描述
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
.
二. 题目分析
给定一个范围[m, n]
,其中 0 <= m <= n <= 2147483647
,返回范围内所有整数的按位与,包括边界m
和n
。比如给定范围为[5, 7]
, 应返回4
。
单看题目描述,可以知道该题涉及到位运算,因此需动笔分析:
对于题目给定的范围[5, 7],可写为:
5: 101
6: 110 -> 100 -> 4
7: 111
再来两个例子:
范围[6, 8]&#x