Leetcode167: Bitwise AND of Numbers Range
2015-11-24 21:04
417 查看
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.
For example, given the range [5, 7], you should return 4.
class Solution { public: int rangeBitwiseAnd(int m, int n) { int i = 0; while(n != m) { m>>=1; n>>=1; i++; } return m<<i; } };
相关文章推荐
- Java条件语句之 switch基本用法
- 设计模式——单例模式
- actionbar标题功能+多个fragment切换+listview展示
- 用二叉树求解代数表达式
- ABAP变量的可见范围
- LINK : fatal error LNK1168: cannot open Debug/CCounter.exe for writing 的解决办法
- AngularJS表达式
- chrome插件编写之新版hello world
- 几个设计模式的例子
- 【NGUI】通过射线检测被遮挡的物体
- NSNotificationCenter通知传参数
- oracle 10g 创建数据库实例卡在3%不动
- 使用JAXP进行SAX解析(XMLReaderFactory、XMLReader 、SAXParserFactory与SAXParser)
- SpringMVC RequestMapping 详解
- iOS_NSURLSessionDownloadTask_显示加载进度_断点续传(网络中断情况).
- codeforce #328D Super M (LCA)
- wamp 安装配置
- Python——函数基础
- android选择相片和拍照保存
- java关键字