Python PodstawyŁatwe

Idealny kwadrat

Szczegółowy przewodnik i implementacja Python dla problemu „idealnego kwadratu”.

Oświadczenie o problemie

Łatwe

Napisz funkcję is_perfect_square(n), która pobiera nieujemną liczbę całkowitą n i zwraca True, jeśli n jest idealnym kwadratem, lub False w przeciwnym razie. Idealny kwadrat to liczba całkowita będąca kwadratem pewnej liczby całkowitej (np. 0, 1, 4, 9, 16, ...).

Ograniczenia
  • 0 <= n <= 10^9

Przykłady

Example 1
Input
n = 16
Output
True
Explanation

16 = 4 × 4, so it is a perfect square.

Example 2
Input
n = 14
Output
False
Explanation

There is no integer whose square is 14.

Example 3
Input
n = 0
Output
True
Explanation

0 = 0 × 0, so it is a perfect square.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla podstaw, 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.