题解 | #数值的整数次方#
数值的整数次方
https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00
class Solution: def Power(self , base: float, exponent: int) -> float: # write code here # 底数为0返回0 if not base: return 0 # 指数为0返回1 if not exponent: return 1 res = base # 指数为正 if exponent > 0: while exponent-1: res *= base exponent -= 1 return res # 指数为负 else: while exponent+1: res *= base exponent += 1 return 1/res