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;
    }
};
相关推荐
码匠许师傅4 小时前
【设计模式精讲】14.外观模式(Facade)
c++·设计模式·uml·外观模式
xxwxx__6 小时前
C++ list 深度解析:从使用原理到模拟实现
开发语言·c++·list
Chester_19996 小时前
CSP202303C.LDAP
开发语言·c++·蓝桥杯·stl
j7~7 小时前
【C++】《unordered系列关联式容器以及哈希底层、哈希冲突、闭散列与开散列完整解析》
c++·哈希算法·开散列·闭散列·unordered_map·unordered_set·哈希底层结构
2402_882893867 小时前
封装红黑树实现map和set —— 从源码到模拟实现
c++·set·map
神仙别闹9 小时前
基于C++ MFC 实现的智慧公交系统
开发语言·c++·mfc
dear_bi_MyOnly9 小时前
函数模块化:企业级项目高效之道
c++·后端·学习
码匠许师傅9 小时前
【设计模式精讲】13.装饰器模式(Decorator)
c++·设计模式·uml·装饰器模式
OPEN-F10 小时前
C++综合实战:面向对象图书管理系统
开发语言·c++
NeoGressAI外贸数字化10 小时前
外贸独立站零询盘排查:从 Google Search Console 到 PageSpeed 的技术实操
开发语言·c++