Recursive reversal
Input
head = [1, 2, 3]
Output
[3, 2, 1]
Using recursion, reverse pointers so the list becomes [3 -> 2 -> 1].
Full lesson preview
Reverse a singly linked list using a recursive approach.
Problem statement
Task
Examples
Input
head = [1, 2, 3]
Output
[3, 2, 1]
Using recursion, reverse pointers so the list becomes [3 -> 2 -> 1].
Input format
Output format
Constraints
Samples
Input
[4, 3, 2, 1]
Output
[1, 2, 3, 4]
Recursively reverse the list to get the correct result.