求x的n次幂。
思路:递归,注意负数
12345678910111213141516
class Solution: def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ # 4 star, 递归 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)