1 line O(logn) Java solution


  • 0
    J
    public double myPow(double x, int n) {
        return n==0?1:(n<0?1/(myPow(x,-(n+1))*x):(n%2==0?myPow(x*x,n/2):x*myPow(x*x,n/2)));
    }
    

Log in to reply
 

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