leetcode50

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)
原文地址:https://www.cnblogs.com/asenyang/p/9826704.html