The integer power of the value of "Sword Finger Offer"
I don't know where I am going, but I am already on my way!
Time is hurried, although I have never met, but I met Yusi, it is really a great fate, thank you for your visit!
Topic : Given a floating-point base of type double and an integer exponent of type int. Find the exponent power of base. Ensure that base and exponent are not 0 at the same time
Example :
示例 1 :
输入:2,3
返回值:8.00000
Code 1:
# -*- coding:utf-8 -*-classSolution:defPower(self, base, exponent):if base ==0and exponent >0:return0if base ==0and exponent <=0:returnFalseif base !=0and exponent >0:return base ** exponent
if base !=0and exponent ==0:return1if base !=0and exponent <0:return1/(base **(-exponent))
Algorithm description: It is discussed in six situations: the base is 0, there are two situations, and the index has three situations, and there are six situations in total.