public class Solution {
    public double MyPow(double x, int n) {
        return Math.Pow(x, (double)n);
    }
}

 

补充一个python的版本:

1 class Solution:
2     def myPow(self, x: float, n: int) -> float:
3         if not n:
4             return 1
5         if n < 0:
6             return 1 / self.myPow(x, -n)
7         if n % 2:
8             return x * self.myPow(x, n-1)
9         return self.myPow(x*x, n/2)

 

posted on 2018-10-21 20:37  Sempron2800+  阅读(123)  评论(0编辑  收藏  举报