dsa · medium
Pow
Compute x raised to the integer power n (x**n). n may be negative; then return the reciprocal of x**(-n). Use a method that is fast enough for |n| up to 2^31 - 1.
Arguments
x— base as a floating numbern— integer exponent, possibly negative
Example
x = 2.00000, n = 10 → 1024.00000.
x = 2.00000, n = -2 → 0.25000.
Constraints
-100.0 < x < 100.0 -2^31 <= n <= 2^31 - 1 n is an integer Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 2.0 10 Expected: 1024.0
Example 2
Input: 2.0 -2 Expected: 0.25