// time O(logN)
// space O(logN)
public double myPow(double x, int n) {
return n >= 0 ? quickMul(x, n) : 1.0 / quickMul(x, -n);
}
double quickMul(double x, int n) {
if (n == 0) {
return 1.0;
}
double y = quickMul(x, n / 2);
return n % 2 == 0 ? y * y : y * y * x;
}
https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/
思路
[ ] 刷15mins
[ ] 刷5mins