- Pow(x, n)
实现 pow(x, n) ,即计算 x 的整数 n 次幂函数(即,xn )。
class Solution {
public:
double quickMulti(double x, long long N) {
if(N == 0) return 1.0;
double y = quickMulti(x, N /2);
return N % 2 == 0 ? y * y : y * y * x;
}
double myPow(double x, int n) {
return n < 0 ? 1 / quickMulti(x, n) : quickMulti(x, -n);
}
};