classSolution:defmyPow(self, x, n):#递归终止的边界条件if n ==0:return1# n分为奇数偶数
m =int(n/2)
half = self.myPow(x,int(n/2))if n%2==0:
res = half*half
return res
elif n >0:#奇数的情况又分为正负两种情况
res = half*half*x
return res
else:
res = half*half/x
return res
C
#define MIN -2147483648#define MAX 2147483647doublemyPow(double x,int n){double res;if(n ==0)return1;if(n <0){
n =-n;
x =1/x;}if(n %2==0){
res =myPow(x*x, n/2);}else
res = x*myPow(x*x, n/2);if(res > MAX || res < MIN)return0;return res;}