题解 | #重排链表#

重排链表

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;
}
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务