题目描述
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
python solution:
# -*- coding:utf-8 -*-
class Solution:
def Power(self, base, exponent):
if exponent==0:
return 1
if exponent==1:
return base
flag = False
if exponent>1:
flag = True
exponent = abs(exponent)
res = base
while exponent>1:
res *= base
exponent -= 1
if flag:
return res
else:
return 1/res