Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes’ values.
For example, Given {1,2,3,4}, reorder it to {1,4,2,3}.
Thoughts
This problem can be easily solved by using HashMap, but due to the requirement, “do this in-place”. So the plan is to complete in three steps. 1 Find the middle element of the list. 2 Do a reverse operation on the second half of the list. 3 Merge the first half and second half in a fashion that picks element from each in order.