Accpted 0 ms c solution


  • 2
    H
    double myPow(double x, int n) {
        if(n == 0)
            return 1.0;
        if(n == 1)
            return x;
        long long int m = n>0 ? n : -n;
        double ans = x;
        long long int cur = 1.0;
        while(cur * 2 < m) {
            cur *= 2;
            ans *= ans;
        }
        ans *= myPow(x, (int)(m-cur));
        return n>0 ? ans : 1.0/ans;
    }

Log in to reply
 

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