201. 数字范围按位与

201. 数字范围按位与


题目链接:201. 数字范围按位与

代码如下:

cpp 复制代码
//参考:https://leetcode.cn/problems/bitwise-and-of-numbers-range/solutions/20925/0he-shui-yu-du-shi-0-by-powcai
class Solution {
public:
    int rangeBitwiseAnd(int left, int right) {
       int count=0;

       while(left!=right)
       {
            left>>=1;
            right>>=1;
            count++;
       }

       return left<<count;
    }
};
相关推荐
Rabitebla15 小时前
【Linux】文件篇(六):Shell 实战——从系统调用到命令行重定向
linux·服务器·c++·笔记·学习
无忧.芙桃1 天前
C++语言原理与实践(二十三):哈希表的实现
c++·链表·哈希算法·散列表·哈希表
AvocadoZeroOneOI1 天前
B4500 [GESP202603 三级] 凯撒密码 详细解题报告
c++·算法
whitelbwwww1 天前
cuBLAS--CUDA高性能线性代数计算库--第一部分
c++·线性代数·gpu算力·cuda c++
eggwyw2 天前
C++设计模式之解释器模式
开发语言·c++
我不会插花弄玉2 天前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴2 天前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus2 天前
C++ explicit 关键字工程实践
开发语言·c++
AIgorithmGEEK2 天前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
一拳一个呆瓜2 天前
【STL】头文件:<cmath>
c++·stl