力扣:50. Pow(x, n)
作者:互联网
1、用递归形式的二分快速幂去求解
class Solution {
public:
double myPow(double x, int n) {
if(n<0)
{
long long m=-(long long)n;
return 1/qpow(x,m);
}
else return qpow(x,n);
}
double qpow(double x,long long n)
{
if(n==0) return 1;
double v=myPow(x*x,n/2);
if(n&1) v=v*x;
return v;
}
};
标签:myPow,int,Pow,50,Solution,力扣,double 来源: https://blog.csdn.net/qq_50917103/article/details/121136770