Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

&nbsp;
Example 1:

Input: x = 2.00000, n = 10
Output: 1024.00000


Example 2:

Input: x = 2.10000, n = 3
Output: 9.26100


Example 3:

Input: x = 2.00000, n = -2
Output: 0.25000
Explanation: 2-2 = 1/22 = 1/4 = 0.25


&nbsp;
Constraints:


	-100.0 &lt; x &lt; 100.0
	-231 &lt;= n &lt;= 231-1
	-104 &lt;= xn &lt;= 104


class Solution:
    def myPow(self, x: float, n: int) -> float:
        self.x = x
        
        if n == 0:
            return 1
        
        isInverted = False
        if n < 0:
            isInverted = True
            n = -1 * n

        result = self.pow(n)
        
        return result if not isInverted else 1 / result
        
    def pow(self, n):
        if n == 1:
            return self.x
        
        if n % 2 == 0:
            p = self.pow(n / 2)
            return p * p
        else:
            return self.x * self.pow(n-1)
class Solution {
    public double myPow(double x, int n) {
        if (n == 0) return 1;
        if (n == 1) return x;
        else if (n == -1) return 1 / x;
        double res = myPow(x, n / 2);
        if (n % 2 == 0) return res * res;
        else if (n % 2 == -1) return res * res * (1/x);
        else return res * res * x;
    }
}
class Solution {
public:
    double myPow(double x, int n) {
        
        if(n==0) return 1;      //anything to the power 0 is 1
        
        if(x==1 || n==1) return x;  //1 to the power anything = 1 or x to the power 1 = x
        
        double ans = 1;
        
        long long int a = abs(n);   //since int range is from -2147483648 to 2147483647, so it can't store absolute value of -2147483648
        
        if(n<0){    //as 2^(-2) = 1/2^2
            if(a%2 == 0) ans = 1/myPow(x*x,a/2);
            else ans = 1/(x * myPow(x,a-1));
        }
        else{
            if(a%2 == 0) ans = myPow(x*x,a/2);
            else ans = x * myPow(x,a-1);
        }
        
        return ans;
        
    }
};
var myPow = function(x, n) {
    return x**n;
};
Pow(x, n)