50. Pow(x, n)

https://leetcode.com/problems/powx-n/description/

class Solution {
public:
    double myPow(double x, int n) {
        return helper(x, n);
    }
    double helper(double x, long n) {
        if (n == 0) return 1;
        if (n < 0)  return 1 / helper(x, -n);
        return n % 2 == 0 ? helper(x * x, n / 2) : x * helper(x, n-1);
    }
};
原文地址:https://www.cnblogs.com/JTechRoad/p/9060091.html