Bitwise AND of Numbers Range
来源:互联网 发布:php 空格占位符 编辑:程序博客网 时间:2024/06/13 02:33
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.
你可以列出一部分连续数的二进制,也许你会发现2^i次方在其中起得作用,也许你想直接从m &到 n,然而,这并没有什么卵用,所得的结果只能是Time Limited。下面的方法,慢慢体会:
class Solution {public: int rangeBitwiseAnd(int m, int n) { int trans = 0; while(m != n) { trans ++; m >>= 1; n >>= 1; } return n<<trans; }};
0 0
- Qt Style Sheet(五) --- QTextTable Class Reference
- HTTP上传文件至服务器
- 【SVN问题,切换SVN用户】记下解决方法
- iOS UIFont 字体名字大全
- mysql索引及类型
- Bitwise AND of Numbers Range
- log4j.properties 详解与配置步骤
- Qt Style Sheet(六) --- QTextTableCell Class Reference
- 面向“对象”和“过程”
- jsp中<c:forEach varStatus="status">的属性值问题
- 例题6.18 绿色的世界 UVa11017
- 提高Android开发效率的9个Web工具
- EXCEL去重统计(条件去重复计数)
- 使用PHP如何获取WSDL中定义的方法列表