LeetCode: Reorder List
摘要:
Given a singly linked listL: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}.我想到的方法是用stack记录下要处理的node,就是从中间开始,后面的node都压入stack。然后再把他们一一插入到原来的list中。比较需要小心的地方时,节点个数为奇数还是偶数的情况不同。因为要给最后 阅读全文
posted @ 2014-02-08 10:22 longhorn 阅读(178) 评论(0) 推荐(0) 编辑