Loading practice problems…
Loading your practice workspace…
Loading code editor…
21 / 29
Sign in
Algorithms/Linked List

Reverse Linked List

easy25 min

Given the head of a singly linked list, reverse the direction of every next pointer.

Return the new head. Each node has the shape { val, next }.

Example 1

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

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

Example 2

Inputhead = [1, 2]

Output[2, 1]

Constraints

  • 0 ≤ number of nodes ≤ 5,000
  • Do not create replacement nodes.
Linked ListPointers