Description
Implement pow(x, n), which calculates x raised to the power n (i.e., x^n). Handle negative exponents and optimize for O(log n) time complexity.
Examples
Input:
x = 2.00000, n = 10Output:
1024.00000Explanation:
2^10 = 1024.
Input:
x = 2.10000, n = 3Output:
9.26100Explanation:
2.1^3 = 9.261.
Input:
x = 2.00000, n = -2Output:
0.25000Explanation:
2^-2 = 1/(2^2) = 0.25.
Constraints
- •
-100.0 < x < 100.0 - •
-2³¹ ≤ n ≤ 2³¹ - 1 - •
n is an integer. - •
-10⁴ ≤ x^n ≤ 10⁴