Bitwise AND of Numbers Range LeetCode solution in C++

1
class Solution {
2
public:
3
int rangeBitwiseAnd(int left, int right) {
4
int t = 0;
5
while (left != right) {
6
left = left >> 1;
7
right = right >> 1;
8
t++;
9
}
10
int ans = left;
11
while (t--) {
12
ans = ans << 1;
13
}
14
return ans;
15
}
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0