c++ solution used log() and exp()


  • 0
    C
    double myPow(double x, int n) {
        int sign = 1;
        if(x<0)
        {
            sign = 0;
            x= -x;
        }
        double res =  exp(n*log(x));
        if(n%2 == 0)
            return res;
        return sign?res:-res;
    }

Log in to reply
 

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