Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 426 Bytes

050.md

File metadata and controls

20 lines (18 loc) · 426 Bytes

50. Pow(x, n)

Solution 1 (O(log(n)))

class Solution(object):
    def myPow(self, x, n):
        """
        :type x: float
        :type n: int
        :rtype: float
        """
        if n == 0:
            return 1
        if n < 0:
            return 1 / self.myPow(x, -n)
        if n & 1:
            return x * self.myPow(x * x, n // 2)
        return self.myPow(x * x, n // 2)