在python中利用递归实现一个幂函数,具体方法如下:
double PowerWithExponentUnsigned(double base, unsigned int exponentUnsigned)
{
// 最小子问题
if(exponentUnsigned == 0)
return 1;
double result = PowerWithExponentUnsigned(base,exponentUnsigned / 2);
result = result * result;
if(exponentUnsigned % 2 == 1)
{
result *= base;
}
return result;
}