[LeetCode]--Pow(x,n)

[LeetCode]--Pow(x,n)
public class Solution {
    public double pow(double x, int n) {
         if(n<0){
            return 1.0/powHelper(x,n);
        }else{
            return powHelper(x, n);
        }
    }
    
    public double powHelper(double x, int n){
       if(n == 0){
            return 1;
        }
        
        double v = powHelper(x, n/2);
        
        if(n % 2 == 0){
            return v*v;
        }else{
            return v*v*x;
        }
    }
}
[LeetCode]--Pow(x,n)

[LeetCode]--Pow(x,n)

上一篇:C#中如何按字节数截取字符串?


下一篇:【年终分享】屌丝玩彩票数据预测(一):离散型马尔可夫链模型实现【附C#代码】