class Solution:
def myPow(self, x: float, n: int) -> float:
point = True
if n < 0:
point = False
n = -n
result = 1
while n > 0:
if n % 2 == 0:
n /= 2
x *= x
result *= x
n -= 1
return result if point else 1/result
leetcode刷题python之Pow(x,n)
最新推荐文章于 2021-12-06 12:53:32 发布