Reorder the list L0 -> L1 -> ... -> Ln as L0 -> Ln -> L1 -> Ln-1 -> L2 -> Ln-2 -> ...: first, last, second, second to last, and so on. Change the pointers, not the values, and return the head.
For 1 -> 2 -> 3 -> 4 the answer is 1 -> 4 -> 2 -> 3.
The tests show a list as a Python list of its values: [1, 2, 3] stands for 1 -> 2 -> 3.
Example 1
Input:
reorder_list(head) # head = 1 -> 2 -> 3 -> 4
Output:
[1, 4, 2, 3]
Example 2
Input:
reorder_list(head) # head = 1 -> 2 -> 3 -> 4 -> 5
Output:
[1, 5, 2, 4, 3]
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.