class Solution(object): def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ if n == -1: return 1.0/x elif n == 0: return 1 elif n == 1: return x else: res = x tmp = Solution() if n % 2 == 1: res = tmp.myPow(x, n//2) ** 2 * x else: res = tmp.myPow(x, n//2) ** 2 return res