Python Recursive


  • 0
    class Solution(object):
        def myPow(self, x, n):
            if n == 0:
                return 1
            if n == 1:
                return x
            half = self.myPow(x, abs(n) / 2)
            return half * half * self.myPow(x, n % 2) if n > 0 else 1 / (half * half * self.myPow(x, n % 2))
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.