【python/leetcode/M/50】Pow(x,n)

版权声明:小明酱私有,私自转载要捶你小胸口哦~ https://blog.csdn.net/alicelmx/article/details/83302893

题目

在这里插入图片描述

实现代码

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 % 2 == 1:
            return x*self.myPow(x*x,n/2)
        else:
            return self.myPow(x*x,n/2)
        

猜你喜欢

转载自blog.csdn.net/alicelmx/article/details/83302893