Python Nozioni di baseFacile

Quadrato perfetto

Guida dettagliata e implementazione Python per il problema del "quadrato perfetto".

Dichiarazione del problema

Facile

Scrivi una funzione is_perfect_square(n) che accetta un intero non negativo n e restituisce True se n è un quadrato perfetto, o False altrimenti. Un quadrato perfetto è un numero intero che è il quadrato di un numero intero (ad esempio, 0, 1, 4, 9, 16, ...).

Vincoli
  • 0 <= n <= 10^9

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Basics come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

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

Apri nell'editor
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

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.