1 开始想得太复杂了,直接一个一个与不就搞定了吗?
class Solution(object):
def rangeBitwiseAnd(self, m, n):
while m<n:
n &= (n-1)
return n
2 time complexity:O(n-m)
3 space complexity: O(1), no extra space
1 开始想得太复杂了,直接一个一个与不就搞定了吗?
class Solution(object):
def rangeBitwiseAnd(self, m, n):
while m<n:
n &= (n-1)
return n
2 time complexity:O(n-m)
3 space complexity: O(1), no extra space