My c solution using recursion


  • 0
    Z
    int rangeBitwiseAnd(int m, int n) {
    if(m == n)
       return m;
    int a =(int)(log(m) / log(2));
    int b = (int)(log(n) / log(2));
    if (a < b)
    {
    	return 0;
    }
    else
    {
    	return pow(2,a) + rangeBitwiseAnd(m-pow(2,a), n - pow(2,a));
    }
    

    }


Log in to reply
 

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