面试经典150题 P201 数字范围按位与 Created:2025-11-25 15:11:13Updated:2025-11-25 15:11:13algorithmalgorithm, leetcode面试经典150题, 位操作字数 96阅读 访客 时间轴 时间轴2025-11-25init 位操作 题目:P201 数字范围按位与https://leetcode.cn/problems/bitwise-and-of-numbers-range/description/?envType=study-plan-v2&envId=top-interview-150找到相同的二进制前缀后再左移回来即可。123456789101112131415class Solution { public: int rangeBitwiseAnd(int left, int right) { int shift = 0; while (left < right) { left = left >> 1; right = right >> 1; shift++; } return right << shift; }};