Problem
Given the head of a linked list L0 -> L1 -> ... -> Ln, rearrange it in place into
L0 -> Ln -> L1 -> Ln-1 -> L2 -> Ln-2 -> ...
alternating one node from the front with one from the back. Change the next pointers, not the values. Return nothing; the tests look at the list starting from the original head.
Example 1
- Input
- 1
- Output
- 2 -> 3 -> 4 → 1 -> 4 -> 2 -> 3
Example 2
- Input
- 1
- Output
- 2 -> 3 -> 4 -> 5 → 1 -> 5 -> 2 -> 4 -> 3
Constraints
0 <= number of nodes <= 5 * 10^41 <= Node.val <= 1000