题目描述
Given a singly linked list L: L 0→L 1→…→L n-1→L n,
reorder it to: L 0→L n →L 1→L n-1→L 2→L n-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}.
思路:
快慢指针找到中间结点,然后根据中间结点,将链表断开,翻转后面部分链表,然后将两个链表合并
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public void reorderList