150 najlepszych wywiadówŁatwe

Pow(x, n)

Szczegółowy przewodnik i implementacja Python dla problemu „Pow(x, n)”.

Oświadczenie o problemie

Łatwe

Zaimplementuj pow(x, n), która oblicza x podniesione do potęgi n (tj. x^n).

Zaimplementuj funkcję myPow(x: float, n: int) -> float.

Ograniczenia
  • -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

Przykłady

Example 1
Input
2.00000, 10
Output
1024.00000
Explanation

2^10 = 1024.

Example 2
Input
2.10000, 3
Output
9.26100
Explanation

2.1^3 = 9.261.

Example 3
Input
2.00000, -2
Output
0.25000
Explanation

2^(-2) = 1/(2^2) = 1/4 = 0.25.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla matematyki i geometrii, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.