Problem : https://leetcode.com/problems/bitwise-and-of-numbers-range/
class Solution:
def rangeBitwiseAnd(self, m: int, n: int) -> int:
mask = 0xFFFFFFFF
while (m & mask) != (n & mask):
# shift mask to left with one bit
# to set m and n one more bit on right to 0
mask <<= 1
return m & mask
No comments:
Post a Comment