加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

[LeetCode] Bitwise AND of Numbers Range

发布时间:2020-12-13 21:04:53 所属栏目:PHP教程 来源:网络整理
导读: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就

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读