Pow(x, n)
Return x to the power n.
Examples
Input: [2,10]
Output:
Input: [2,-2]
Output:
Hints
Consider using recursion to break down the exponentiation into smaller subproblems, leveraging the mathematical property that \(x^n = (x^{n/2})^2\) when \(n\) is even.
For negative exponents, first compute the positive exponent and then take the reciprocal of the result to handle the inversion efficiently.
Optimize the base case to return 1 when the exponent is 0, and handle the case where the exponent is odd by multiplying the result by \(x\) once more after the recursive step.
Related Problems
Pow(x, n)
Return x to the power n.