My simple Java solution Pow [easy to understand]


  • 0
    G

    class Solution {
    public double myPow(double x, int n) {

        if(n ==0){return 1;}
        double temp = myPow(x, n/2);
        
        if(n < 0){
        x = 1/x;
        }
        
        return (n%2 == 0) ? temp*temp : x * temp * temp;
    }
    

    }


Log in to reply
 

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