Leetcode 50 Solution

This article provides solution to leetcode question 50 (powx-n)

https://leetcode.com/problems/powx-n

Solution

class Solution:
    def myPow(self, x: float, n: int) -> float:
        if n < 0:
            return 1 / self.myPow(x, -n)
        elif n == 0:
            return 1

        if n % 2 == 0:
            return self.myPow(x * x, n // 2)
        else:
            return self.myPow(x * x, n // 2) * x