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;
    }
};
相关推荐
ebiobiz1 天前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
hetao17338371 天前
2026-09-29 hetao1733837 的刷题记录
c++·算法
:mnong1 天前
几何内核“四大金刚“:ACIS、Parasolid、CGM、Open CASCADE 核心特征深度解析
c++·cad·cax
by209991 天前
从 malloc/free 到 new/delete:真正理解 C++ 中的内存管理与对象生命周期
c语言·c++·经验分享·动态内存管理
m0_380743871 天前
Qt侧边栏布局的实现示例
开发语言·c++
汉克老师1 天前
GESP2026年9月认证C++五级( 第三部分编程题(1、哥德巴赫猜想))精讲
c++·gesp·小学生·学c++编程
小灰灰搞电子1 天前
C++ final 关键字详解:从虚函数到类继承的完整指南
c++·final
weixin_307779131 天前
C++代码实现MATLAB中的pade函数功能
开发语言·c++·算法·matlab
神仙别闹1 天前
基于C++实现的(控制台)学校开课查询系统
开发语言·c++
Dylan的码园1 天前
A+B问题 进制处理【逻辑控制 运算符】
c++·算法