A singly linked list is a chain of nodes. Each node holds a value and points to the next node, like the coaches of a train joined one after another.
Reverse the chain, so the last node becomes the first node, and return the new list.
How the judge passes the data
Examples
Example 1:
Input: head = [7,8,9]
Output: [9,8,7]
Explanation: The order 7, 8, 9 becomes 9, 8, 7.
Example 2:
Input: head = [4,2,6,6]
Output: [6,6,2,4]
Explanation: Read the list from the back: 6, 6, 2, 4.
Example 3:
Input: head = [5]
Output: [5]
Explanation: A list with one node stays the same.