50. Pow(x, n)

def myPow(self, x, n):
        """
        :type x: float
        :type n: int
        :rtype: float
        """
        res = 1
        if n < 0:
            x = 1 / x
            n = -n
        while n:
            if n % 2:
                res *= x
            x *= x
            n >>= 1
        return res

results matching ""

    No results matching ""