LeetCode 50, Medium. Topics: Math, Recursion. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:
Problem
Implement pow(x, n), which calculates x raised to the power n (i.e., x<sup>n</sup>).
Examples
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
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Grind, NeetCode 150, NeetCode 250, NeetCode All. Last modified on September 7, 2026