Simple example
Input
head = [1, 2, 3]
Output
[3, 2, 1]
Reversing the list [1 -> 2 -> 3] yields [3 -> 2 -> 1].
Full lesson preview
Reverse a singly linked list using an iterative in-place algorithm.
Problem statement
Task
Examples
Input
head = [1, 2, 3]
Output
[3, 2, 1]
Reversing the list [1 -> 2 -> 3] yields [3 -> 2 -> 1].
Input format
Output format
Constraints
Samples
Input
[1, 2, 3, 4]
Output
[4, 3, 2, 1]
Iteratively reverse the links to produce the reversed list.