# 递归classSolution(object):defmyPow(self, x, n):"""
:type x: float
:type n: int
:rtype: float
"""defquickmul(N):if N ==0:return1.0
y = quickmul(N/2)if N%2==0:return y*y
else:return y*y*x
return quickmul(n)if n>0else1/quickmul(-n)
# 非递归classSolution(object):defmyPow(self, x, n):"""
:type x: float
:type n: int
:rtype: float
"""defquickmul(N):
ans =1.0
x_con = x
while N>0:if N%2==1:
ans *= x_con
x_con *= x_con
N //=2return ans
return quickmul(n)if n>0else1.0/quickmul(-n)