You are given a linked list with the nodes L0, L1, L2, ..., Ln, from the first node to the last node.
Rearrange the nodes in this order: L0, Ln, L1, Ln-1, L2, Ln-2, and so on. In other words, take one node from the front, then one from the back, and keep taking turns until every node is used.
You must move the nodes, not change the values stored in them.
How the judge passes the data
Examples
Example 1:
Input: head = [1,2,3,4,5,6]
Output: [1,6,2,5,3,4]
Explanation: Take 1 (front), 6 (back), 2, 5, 3, 4.
Example 2:
Input: head = [10,20,30]
Output: [10,30,20]
Explanation: Take 10 (front), 30 (back), then 20 is left.
Example 3:
Input: head = [8]
Output: [8]
Explanation: A list with one node stays the same.