Title description
Implement the function double Power (double base, int exponent), find the exponent power of base. Don't use library functions, and don't need to consider large numbers.
Ideas
Code
class Solution:
def myPow(self,x:float,n:int)->float:
if x == 0:
return 0
res = 1
if n < 0:
x, n = 1/x, -n
while n:
x *= x
n >>= 1 #(n除以2)
if n & 1:
res *= x
return res