[leetcode] Bitwise AND of Numbers Range
Bitwise AND of Numbers Range
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.
Credits:
Special thanks to @amrsaqr for adding this problem and creating all test cases.
class Solution
{
public:
int rangeBitwiseAnd(int m, int n)
{
int ret = m;
int a = m, b = n;
int lena = , lenb = ; if(m == n)
return m; while(a >>= )
lena++; while(b >>= )
lenb++; if(lena == lenb)
{
for(int i = m + ; i <= n; i++)
{
ret &= i;
if(i == INT_MAX)
break;
}
}
else
ret = ; return ret;
}
};
[leetcode] Bitwise AND of Numbers Range的更多相关文章
- [LeetCode] 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)
201. 数字范围按位与 201. Bitwise AND of Numbers Range 题目描述 给定范围 [m, n],其中 0 <= m <= n <= 214748364 ...
- 【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解题报告—— Number of Islands & Bitwise AND of Numbers Range
1. Number of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of island ...
- 【刷题-LeetCode】201 Bitwise AND of Numbers Range
Bitwise AND of Numbers Range Given a range [m, n] where 0 <= m <= n <= 2147483647, return t ...
- leetCode191/201/202/136 -Number of 1 Bits/Bitwise AND of Numbers Range/Happy Number/Single Number
一:Number of 1 Bits 题目: Write a function that takes an unsigned integer and returns the number of '1' ...
- [LeetCode] 201. Bitwise AND of Numbers Range ☆☆☆(数字范围按位与)
https://leetcode.com/problems/bitwise-and-of-numbers-range/discuss/56729/Bit-operation-solution(JAVA ...
- 【leetcode】Bitwise AND of Numbers Range(middle)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- React JS 基础知识17条
1. 基础实例 <!DOCTYPE html> <html> <head> <script src="../build/react.js" ...
- 开发一款高端大气上档次的android应用需要必备的知识——记于2013年末
Android入门还是很简单的,看两本书,翻阅几篇文章,搭建了开发环境就算入门了.可是怎样开发一款完备的android应用呢,开发一款高端的android应用又需要那些知识呢,作者根据几年的开发经验做 ...
- NPM使用详解(下)
NPM使用详解(下) *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !impo ...
- 基于tiny4412的Linux内核移植 -- 设备树的展开
作者信息 作者: 彭东林 邮箱:pengdonglin137@163.com QQ:405728433 平台简介 开发板:tiny4412ADK + S700 + 4GB Flash 要移植的内核版本 ...
- 免费下载:用于原型设计的 iOS 7 线框图
André Revin 使用 Illustrator 创建 iOS7 iPhone 5 的样机原型.这是一个像素完美的线框样机,可以帮助超级轻松的打造你的原型.你可以免费下载源文件,并在工作中使用. ...
- servlet中的细节
Get方法有大小限制:1024个字符.这些信息使用 Query_String头传递,并通过Query_String环境变量访问.Post方法:请求体信息使用FromData头传递.读取所有表单参数:g ...
- 图片轮播(左右切换)--JS原生和jQuery实现
图片轮播(左右切换)--js原生和jquery实现 左右切换的做法基本步骤跟 上一篇文章 淡入淡出 类似,只不过修改了一些特定的部分 (1)首先是页面的结构部分 对于我这种左右切换式 1.首先是个外 ...
- 设计模式--建造者(Builder)模式
将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示 --<设计模 ...
- 在C#后端处理一些结果然传给前端Javascript或是jQuery
在C#后端处理一些结果然传给前端Javascript或是jQuery,以前Insus.NET有做过一个例子<把CS值传给JS使用 >http://www.cnblogs.com/insus ...
- KTV点歌系统
经过十多天的艰苦奋战,MyKTV点歌系统终于成型,从刚开始接到项目的茫然,到完成项目时的喜悦,整个过程的艰辛和付出只有自己知道.虽然这个项目还有许多需要完善的地方,譬如添加歌词信息,实现窗体的美化等, ...