Pow(x, n)
Total Accepted: 67450 Total Submissions: 250035 Difficulty: Medium
class Solution(object): def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ if n==0: return 1 tmp = self.myPow(x, abs(n)/2) tmp = tmp * x * tmp if n%2 else tmp * tmp return tmp if n > 0 else float(1)/tmp
Idea
Please see similar idea at https://czxttkl.com/?p=1000