题解 | 数值的整数次方
数值的整数次方
https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00
class Solution { private: double multiplay(double x, int n){ if(n == 0) return 1; double tmp = multiplay(x, n / 2); return n % 2 ? tmp * x * tmp : tmp * tmp; } public: double Power(double base, int exponent) { return exponent >=0 ? multiplay(base,exponent):1 /multiplay(base, -exponent); } };