Reverse Linked List
Reverse a singly linked list recursively by leveraging the call stack to rewire successor pointers from the tail back to the head.
01The problem
Given the head of a singly linked list, reverse the list, and return the reversed list.
Solve this problem recursively.
| Input | Output | Why |
|---|---|---|
[1, 2, 3, 4, 5] | [5, 4, 3, 2, 1] | List reversed completely |
[1, 2] | [2, 1] | Two-node list swapped |
[] | [] | Empty list remains empty |
Constraints: Number of nodes is in range [0, 5000], -5000 <= Node.val <= 5000.
Loading the rest of the lesson…