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;
}
};