剑指 Offer 16. 数值的整数次方
作者:互联网
快速幂。
class Solution {
public:
double qpow(double x, long long n) {
double res = 1;
while (n) {
if (n & 1) res *= x;
x = x * x;
n >>= 1;
}
return res;
}
double myPow(double x, int n) {
return n >= 0 ? qpow(x, n) : 1.0 / qpow(x, -(long long)n);
}
};
标签:qpow,return,Offer,double,16,long,res,次方 来源: https://www.cnblogs.com/fxh0707/p/15041469.html