40ms Solution By C


  • 4
    B
    int rangeBitwiseAnd(int m, int n) {
        int i;
        for(i=0;m!=n;m>>=1,n>>=1)i++;
        return m<<i;
    }

  • 0
    P

    This solution is really cool. Could you please give an explanation of what exactly is happening? I did dry this on paper and can't figure out the reasoning behind this.


Log in to reply
 

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