201. Bitwise AND of Numbers Range
2016-05-11 18:29
232 查看
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 二进制编码中 同为1的前缀.
For example, given the range [5, 7], you should return 4.
[思路]
等价于 求 m 与 n 二进制编码中 同为1的前缀.
class Solution { public: int rangeBitwiseAnd(int m, int n) { int bit = 0; while(m!=n) { m>>=1; n>>=1; bit++; } return m<<bit; } };
相关文章推荐
- PHPWord利用模板替换字符串生成精确的word文档
- java 随机生成四位数验证码
- java 彩票36选6
- springMVC+mybatis 进行单元测试时 main SqlSessionFactoryBean - Parsed configuration file: 'class path resource' 无限的读取xml文件
- Runner之记计账项目的典型用户分析
- 居乐随笔
- Docker背后的容器管理——Libcontainer深度解析
- 每天定时提醒 每周定时提醒
- [置顶] Scanner和 BufferedReader 的区别(待解决)scanner方式是错的
- 【从零学习openCV】IOS7下的人脸检測cvload错误解决
- Android 综合揭秘 —— 全面剖释 Service 服务
- 又回来了~继续记录工作上的技术点
- LintCode:二叉树的层次遍历
- mocha+ React + enzyme 单元测试
- Linux IO模式及 select、poll、epoll详解
- 读取iOS设备的代理设置
- 新第三方库,防止键盘遮挡输入框
- vim 一键编译JAVA,c++
- 数据表的水平拆分
- Web前端图表绘制JQuery插件jqplot