150 principais entrevistasFácil

Lista vinculada reversa

Guia detalhado e implementação de Python para o problema de 'Lista vinculada reversa'.

Declaração do problema

Fácil

Dado o cabeçalho de uma lista vinculada individualmente, inverta a lista e retorne a lista invertida.

A lista vinculada é representada como uma lista de valores. Implemente uma função reverseList(head: list) -> list que pega uma lista que representa a lista vinculada e retorna a lista invertida.

Restrições
  • The number of nodes in the list is in the range [0, 5000]
  • -5000 <= Node.val <= 5000

Exemplos

Example 1
Input
[1,2,3,4,5]
Output
[5,4,3,2,1]
Explanation

The original list is 1->2->3->4->5. After reversing, it becomes 5->4->3->2->1.

Example 2
Input
[1,2]
Output
[2,1]
Explanation

The original list is 1->2. After reversing, it becomes 2->1.

Example 3
Input
[]
Output
[]
Explanation

An empty list reversed is still an empty list.

Need a Hint?
Considere usar estruturas de dados específicas de listas vinculadas, como conjuntos ou heaps.
Edge Cases to Watch
  • Estruturas de entrada vazias
  • Entradas de elemento único
  • Grandes limites numéricos

Pronto para resolver?

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

Abrir no 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

Recursos Python recomendados

Expanda seu conhecimento com tutoriais interativos relacionados, folhas de dicas e comparações de código.