We’re preparing your current view and syncing the latest data.
Given the head of a singly linked list, reverse the list and return the reversed list.
The input is the head of a singly linked list.
Return the head of the reversed linked list.
The number of nodes in the list is in the range [0, 5000]. -5000 <= Node.val <= 5000
Example 1
Input
head = [1,2,3,4,5]
Output
[5,4,3,2,1]
Explanation
The linked list 1 -> 2 -> 3 -> 4 -> 5 is reversed to 5 -> 4 -> 3 -> 2 -> 1.