c solution


  • 0
    A

    int rangeBitwiseAnd(int m, int n) {
    if(m==0)
    return 0;
    if(n==m)
    return n;
    int x=1;
    m=m>>1;
    n=n>>1;

    while((m<n)&&(m!=0))
    {
        x++;
        m = m>>1;
        n = n>>1;
    }
    
    return m<<x;
    

    }


Log in to reply
 

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