Pow(x, n)
Input:
2.00000, 10
Output:
1024.00000Input:
2.10000, 3
Output:
9.26100class Solution(object):
def myPow(self, x, n):
if n == 0:
return 1.0
elif n < 0:
return 1 / self.myPow(x, -n)
elif n % 2 == 1:
return self.myPow(x*x,n/2)*x
else:
return self.myPow(x*x,n/2)Last updated