Reverse a singly linked list and return the new head. Each node has a val and a next (the next node, or None at the end).
The tests show a list as a Python list of its values: [1, 2, 3] stands for 1 -> 2 -> 3.
Example 1
Input:
reverse_list(head) # head = 1 -> 2 -> 3 -> 4 -> 5
Output:
[5, 4, 3, 2, 1]
Example 2
Input:
reverse_list(head) # head = empty list
Output:
[]
0 <= number of nodes <= 100000-10**9 <= val <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.