标签:描述 ase one coding abs power python 一个 utf-8
题目描述
给定一个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
标签:描述 ase one coding abs power python 一个 utf-8
原文地址:https://www.cnblogs.com/bernieloveslife/p/10423092.html