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,5,6}, reorder it to {1,6,2,5,3,4}.
代码:
解题思路:写一个反转函数reverseList,一个合并函数mergeList,然后将链表分成两个独立的链表,利用合并函数进行合并,完成重新排序。