The problem. Given the head of a singly linked list, reverse the list and return the new head. Every arrow should point the other way.
Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Input: head = [1, 2]
Output: [2, 1]
Input: head = []
Output: []Members only · free account
The rest of this lesson, with 5 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson