50. Pow(x, n)
程序员文章站
2022-07-15 12:48:03
...
import math
class Solution:
def myPow(self, x: float, n: int) -> float:
return math.pow(x,n)
class Solution:
def myPow(self, x: float, n: int) -> float:
res = 1
if n == 0:
return 1
elif n < 0:
x = 1/x
n = -n
cur = x
k = n
while (k > 0):
if k % 2 == 1:
res *= cur
cur *= cur
k //= 2
return res
上一篇: 50. Pow(x, n)
下一篇: 50. Pow(x, n)