Pow(x, n)

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

Constraints

  • -100.0 < x < 100.0
  • -2^31 <= n <= 2^31 - 1
  • n is an integer.
  • Either x is not zero or n > 0.
  • -10^4 <= x^n <= 10^4
Saving… · 2 lines
class Solution:
def power(self, x: float, n: int) -> float:
Console

Click Run to execute sample tests.