class Solution:
def myPow(self, x: float, n: int) -> float:
if n == 0:
return 1
elif n % 2 != 0:
if n > 0:
return x*self.myPow(x,n-1)
else:
return 1/(x*self.myPow(x,-n-1))
else:
if n > 0:
return self.myPow(x*x,int(n/2))
else:
return 1/self.myPow(x*x,int(-n/2))
github项目地址:https://github.com/JockWang/LeetCode-Python