201. Bitwise AND of Numbers Range
来源:互联网 发布:云计算课程大纲 编辑:程序博客网 时间:2024/06/05 19:17
//time exceededclass Solution {public: int rangeBitwiseAnd(int m, int n) { if(m==n) return m; int a=m; while(m<n) { a&=m++; if(a==0) return 0; } return a; }};
//64msclass Solution {public: int rangeBitwiseAnd(int m, int n) { if(m==n) return m; return 2*rangeBitwiseAnd(m/2,n/2); }};
class Solution {public: int rangeBitwiseAnd(int m, int n) { if(m==n) return m; if(m&n==0) return 0; return 2*rangeBitwiseAnd(m/2,n/2); }};
class Solution {public: int rangeBitwiseAnd(int m, int n) { if(m==n) return m; int a=1; while(m<n) { if(m&n==0) return 0; a*=2; m/=2; n/=2; } a*=m; return a; }};
0 0
- Arrays类和Collections的运用
- C#如何以管理员身份运行程序
- js 实现类似 Java 中的 StringBuilder
- leetcode——47——Permutations II
- 总结matlab中non-singleton含义
- 201. Bitwise AND of Numbers Range
- Http协议中关于Content-Length和Chunk
- Swift中的iOS设计模式(一)
- 堆与栈
- 吾解 extern
- Jmeter测试MySQL数据库实例
- C++基础和STL,Effective C++笔记
- OC 字符串NSString 创建 拼接 插入 修改 删除 查找判断等基础用法
- ACM--贪心--数学--A-B Game--水