LeetCode 201 Bitwise AND of Numbers Range 位运算 难度:0
https://leetcode.com/problems/bitwise-and-of-numbers-range/
[n,m]区间的合取总值就是n,m对齐后前面一段相同的数位的值
比如
5:101
7:111
结果就是
4:100
class Solution {
public:
int rangeBitwiseAnd(int m, int n) {
int len = 0;
long long tmp = 1;
for(;tmp <= n || tmp <= m;len++){tmp<<=1;}
int ans = 0;
for(int i = len - 1;i>=0;i--){
if(((1<<i) & n) == ((1<<i) & m))ans |= (1<<i)&m;
else break;
}
return ans;
}
};
LeetCode 201 Bitwise AND of Numbers Range 位运算 难度:0的更多相关文章
- leetcode 201. Bitwise AND of Numbers Range(位运算,dp)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] 201. Bitwise AND of Numbers Range ☆☆☆(数字范围按位与)
https://leetcode.com/problems/bitwise-and-of-numbers-range/discuss/56729/Bit-operation-solution(JAVA ...
- Java for LeetCode 201 Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode#201] Bitwise AND of Numbers Range
Problem: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of al ...
- 【LeetCode】201. Bitwise AND of Numbers Range 解题报告(Python)
[LeetCode]201. Bitwise AND of Numbers Range 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/prob ...
- 【LeetCode】201. Bitwise AND of Numbers Range
Bitwise AND of Numbers Range Given a range [m, n] where 0 <= m <= n <= 2147483647, return ...
- 【刷题-LeetCode】201 Bitwise AND of Numbers Range
Bitwise AND of Numbers Range Given a range [m, n] where 0 <= m <= n <= 2147483647, return t ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- 201. Bitwise AND of Numbers Range
题目: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all num ...
随机推荐
- NOIP2016普及组复赛解题报告
提高组萌新,DAY1DAY2加起来骗分不到300,写写普及组的题目聊以自慰. (附:洛谷题目链接 T1:https://www.luogu.org/problem/show?pid=1909 T2:h ...
- 高通android开发缩写
1.TLMM MSM TLMM pinmux controller,Qualcomm MSM integrates a GPIO and Pin mux/config hardware, (TOP L ...
- 蚁群算法简介(part3: 蚁群算法之更新信息素)
信息素的局部更新策略 每只蚂蚁在构造出一条从起点到终点的路径后,蚁群算法还要求根据路径的总长度来更新这条路径所包含的每条边上信息素的浓度(在旅行商问题中每座城市是图中的一个节点,城市两两间有一条边 ...
- [CF752D]Santa Claus and a Palindrome(优先队列,贪心乱搞)
题目链接:http://codeforces.com/contest/752/problem/D 题意:给长度为k的n个字符串,每一个字符串有权值,求构造一个大回文串.使得权值最大. 因为字符串长度都 ...
- Tomcat 6 --- JNDI详解
点击查看推荐博文
- 为什么不要使用Response.Close()
不要使用Response.Close() 不要使用Response.Close() 不要使用Response.Close() 1 因为:Close()方法会调用HttpWo ...
- solar system by HTML5
solar system by HTML5 星际穿越感觉很炫酷啊,网易貌似做了个专题在朋友圈挺火的.用canvas模拟太阳系,嗯,不错昂! 代码及效果 See the Pen GgpRjN by Na ...
- windows apache开启url rewrite
加载Rewrite模块: 在conf目录下httpd.conf中找到 LoadModule rewrite_module modules/mod_rewrite.so 这句,去掉前边的注释符号“#”, ...
- bootstrap 实战入门教程(一)
说起响应式前端框架,比较而言,bootstrap还是不错的,虽然可能很多文档都是英文的.今天就整理下自己在学习及使用bootstrap3时的重要知识点和使用案例 参考资料: runoob的bootst ...
- jmx相关资料
http://www.ibm.com/developerworks/cn/java/j-lo-jse63/ http://blog.csdn.net/javafreely/article/detail ...