Share my simple java solution.


  • 0
    J
    public int rangeBitwiseAnd(int m, int n) {
        int factor=1;
        while(m!=n){
            factor=factor*2;
            m=m>>1;
            n=n>>1;
        }
        return m*factor;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.