BiruLyu
5/25/2017 - 6:43 PM

201. Bitwise AND of Numbers Range.java

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;
public class Solution {
    public int rangeBitwiseAnd(int m, int n) {
        while( m < n){
            n &= (n-1);
        }
        return n;
    }
}