/50. Pow(x, n)

50. Pow(x, n)

Medium
Probability38.3% acceptance

Implement a function that computes the value of a floating-point base raised to an integer exponent. Given a floating-point number base and an integer exponent, return base raised to the power of exponent. The result should be a floating-point number.

Example 1

Input: base=3.0, exponent=4

Output: 81.0

Explanation: 3^4 = 81

Example 2

Input: base=0.5, exponent=6

Output: 0.015625

Explanation: 0.5^6 = 0.015625

Example 3

Input: base=5.0, exponent=-1

Output: 0.2

Explanation: 5^-1 = 1/5 = 0.2

Constraints

  • -100.0 < base < 100.0
  • -231 <= exponent <= 231 - 1
  • exponent is an integer
  • Either base != 0 or exponent > 0
  • -104 <= base**exponent <= 104
Python (current runtime)

Case 1

Input: base=1.5, exponent=3

Expected: 3.375

Case 2

Input: base=4.0, exponent=-2

Expected: 0.0625

Case 3

Input: base=-2.0, exponent=5

Expected: -32.0

Case 4

Input: base=10.0, exponent=0

Expected: 1.0