题解 | #重排链表#
重排链表
http://www.nowcoder.com/practice/3d281dc0b3704347846a110bf561ef6b
public class Solution {
public void reorderList(ListNode head) {
if(head==null||head.next==null||head.next.next==null){
return ;
}
ListNode fast = head;
ListNode pre ,last;
while(fast!=null&&fast.next!=null&&fast.next.next!=null){
pre = fast;
while(pre.next.next!=null){
pre = pre.next;
}
last = pre.next;
last.next = fast.next;
fast.next = last;
pre.next = null;
fast = fast.next.next;
}
return;
}
}