leetcode 201. Bitwise AND of Numbers Range
来源:互联网 发布:个性字体设计软件 编辑:程序博客网 时间:2024/06/06 17:12
201. 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.
求公共的2进制前缀。
5 - 0101
7 - 0111
5到7之间的数公共的位就是 0100 -> 4
class Solution {public: int rangeBitwiseAnd(int m, int n) { int count = 0; while ( m != n ) { m>>=1; n>>=1; count++; } return m<<count; }};
阅读全文
0 0
- 【LeetCode算法练习(C++)】Search for a Range
- Python《机器学习实战》读书笔记(三)——决策树
- docker使用容器镜像加速器
- 读《Maven实战》
- IDEA工具使用01 -- 基本配置使用
- leetcode 201. Bitwise AND of Numbers Range
- 进程管理API之find_vpid
- mt6735 [Speech]如何在代码中默认内置VM log抓取所需的参数
- 表单控制接口
- docker中的centos7使用时报Failed to get D-BUS connection: Operation no permitted
- 微信公众号开发系统,php开发公众号营销系统
- 复选框回显
- 目录—总目录
- 差评近一半,用 Python 分析胡歌的《猎场》到底值不值得看?