Tag:leetcode fb
Category:Leetcode
Article From:https://www.cnblogs.com/JTechRoad/p/9060091.html

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);
    }
};

 

Link of this Article: 50. Pow(x, n)

Leave a Reply

Your email address will not be published. Required fields are marked *