- 指数分为正负数即可
- 现将负数转换为正数,最后再求倒数返回
public class Solution {
public double Power(double base, int exponent) {
//判断指数是正数还是负数
int fu=0;
if(exponent<0)
{
fu=1;
exponent=-exponent;
}
double ans=1.0d;
for(int i=0;i<exponent;i++)
{
ans*=base;
}
if(fu==1)
{
return 1/ans;
}
return ans;
}
}