Given the head of a singly linked list, reverse the direction of every next pointer.
Return the new head. Each node has the shape { val, next }.
Inputhead = [1, 2, 3, 4, 5]
Output[5, 4, 3, 2, 1]
The last node, 5, becomes the new head. Following the reversed links visits 5, 4, 3, 2, and then 1.
Inputhead = [1, 2]
Output[2, 1]
Reversing the link makes 2 the new head and 1 the last node.
0 ≤ number of nodes ≤ 5,000