leecode_201 Bitwise AND of Numbers Range
2016-05-27 04:12
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.
class Solution {
public:
int rangeBitwiseAnd(int m, int n) {
int i=0;
while(m!=n){
m>>=1;
n>>=1;
i++;
}
return m<<i;
}
};
For example, given the range [5, 7], you should return 4.
class Solution {
public:
int rangeBitwiseAnd(int m, int n) {
int i=0;
while(m!=n){
m>>=1;
n>>=1;
i++;
}
return m<<i;
}
};
相关文章推荐
- AdaBoost算法
- centos ssh免密码秘钥登录
- OSChina 周五乱弹 ——跳广场舞的大妈问我有没有老伴几个意思?
- JSP系列:(4)JSP进阶-EL表达式和JSP标签
- leetcode $42 in cpp
- 利用GitHub Pages和Hexo搭建个人博客
- 六、SpringBoot发布
- LeetCode 330. Patching Array
- FPGA视觉从入门到放弃——削苹果剩下的小波矩
- Linux下的基于Pthread的多线程Socket编程
- 30学习写论坛-6
- 安装app到Simulator
- (Jmeter 五)JMeter监控web服务器性能
- 使用UUID生成验证码
- UITableViewCell添加自定义view,在cell选中高亮时,view消失,取消高亮时,view又出现
- 一、Linux常用命令与问题
- 软件测试
- 看到别人的鸡汤
- 框架 day38 SVN安装及使用,SSH练习项目CRM,环境搭建(myeclipse hibernate 反转引擎生成PO和映射)
- 一、Linux常用命令