Given the head of a linked list, the task is to reverse this list and return the reversed head.
Example 1
Input: Linked list: 10 -> 20 -> 30 -> 40 -> 50
Output: 50 -> 40 -> 30 -> 20 -> 10
Explanation: The linked list is reversed such that the last node becomes the head, and the head becomes the last node.
Example 2
Input: Linked list: -3 -> -2 -> -1 -> 0 -> 1
Output: 1 -> 0 -> -1 -> -2 -> -3
Explanation: The linked list is reversed while maintaining the relative positions of negative and positive numbers.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
10 20 30 40 50
50 40 30 20 10
3 2 1 0 1
1 0 1 2 3