Leetcode50 Pow(x,n)

代码:
 

class Solution {
    public double myPow(double x, int n) {
        if(n==0)return 1;
        if(n>0){
            return quickMul(x,n);
        }else{
            return 1/quickMul(x,-n);
        }
        

    }
    public double quickMul(double x,int n){
        if(n==0){
            return 1.0;
        }
        double y = quickMul(x,n/2);
        return n%2==0 ? y*y:y*y*x;
    }
}

你可能感兴趣的:(java,开发语言)