[LeetCode] Bitwise AND of Numbers Range

前端之家收集整理的这篇文章主要介绍了[LeetCode] 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.

解题思路

① n&(n⑴),可以去除n的最低位的1。
② 从n1直与到m,可以去掉的1就是n和m的右端不相等的部份的1。
例如对以下m和n:
110100111101

猜你在找的PHP相关文章