algorythms
In-place List Reversal
LC #206Easy

Reverse Linked List

In-place List Reversal
AmazonGoogleMetaMicrosoftApple

Problem

Reverse a singly linked list in-place.

linked-list

Constraints

  • 0 ≤ n ≤ 5000
  • -5000 ≤ Node.val ≤ 5000
  • Both iterative and recursive solutions accepted

Example

Inputhead = [1, 2, 3, 4, 5]
Output[5, 4, 3, 2, 1]

Hints — reveal one at a time