Python Nozioni di baseFacile

Inverso di un numero

Guida dettagliata e implementazione Python per il problema "Inverso di un numero".

Dichiarazione del problema

Facile

Scrivi una funzione reverse_number(n) che accetta un numero intero non negativo n e restituisce il numero intero formato invertendo le sue cifre. Gli zeri iniziali nel risultato invertito dovrebbero essere eliminati (ad esempio, invertendo 100 si ottiene 1).

Vincoli
  • 0 <= n <= 10^9

Esempi

Example 1
Input
n = 1234
Output
4321
Explanation

Reversing the digits of 1234 gives 4321.

Example 2
Input
n = 100
Output
1
Explanation

Reversing 100 gives 001, which is 1 as an integer.

Example 3
Input
n = 5
Output
5
Explanation

A single digit reversed is itself.

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.