recursive solution using JAVA


  • 0
    R

    public double myPow(double x, int n) {
    if(n == Integer.MIN_VALUE) return 1/(myPow(x, Integer.MAX_VALUE)x);
    if(n<0) return 1/myPow(x, (-1)n);
    if(n==0) return 1.0;
    if(n==1) return x;
    double temp = myPow(x, n/2);
    if(n % 2 ==0) {
    return temp
    temp;
    } else {
    return temp
    temp*x;
    }
    }


Log in to reply
 

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