#7EasyLinked Lists· Pointer Reversal
Reverse Linked List
Input format
head: array of integers representing the list from head to tail (may be empty)
Output format
Array of integers: the reversed list from its new head to its tail
Examples
Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Every pointer is flipped, so 5 becomes the new head.
Input: head = []
Output: []
An empty list stays empty.
Constraints
- 0 <= number of nodes <= 5000
- -5000 <= Node.val <= 5000
Study first
- #linked-lists
- #pointers
- #iteration
