myPow(x,n)


  • 0
    V
    double myPow(double x, int n) {
        double temp;
        
        if (n == 0) {
            return 1;
        }
        temp = myPow(x, n/2);
        
        if (n%2 == 0) {
            return temp*temp;
        }
        else {
            if (n > 0)  {
                return temp*temp*x;
            }
            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.