Skip to content

Commit e0168c2

Browse files
authored
Create 201_bitwise_and_of_numbers_range.cpp (qiyuangong#29)
* Create 201_bitwise_and_of_numbers_range.cpp, by @bhanu1131
1 parent 5dadae9 commit e0168c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** time complexity : O(logN). N = min(m, n) **/
2+
3+
class Solution {
4+
public:
5+
int rangeBitwiseAnd(int m, int n) {
6+
int cnt = 0;
7+
while(m < n) {
8+
m = m >> 1;
9+
n = n >> 1;
10+
cnt++;
11+
}
12+
return n<<cnt;
13+
}
14+
};

0 commit comments

Comments
 (0)