Skip to content

Instantly share code, notes, and snippets.

@BiruLyu
Created May 25, 2017 18:43
Show Gist options
  • Select an option

  • Save BiruLyu/798ca552e490008d0e9d5e2e787883fe to your computer and use it in GitHub Desktop.

Select an option

Save BiruLyu/798ca552e490008d0e9d5e2e787883fe to your computer and use it in GitHub Desktop.
public class Solution {
public int rangeBitwiseAnd(int m, int n) {
while( m < n){
n &= (n-1);
}
return n;
}
}
class Solution(object):
def rangeBitwiseAnd(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
res = 0;
while(m != n):
m = m >> 1;
n = n >> 1;
res += 1;
return m << res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment