/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public void reorderList(ListNode head) {
        if(head == null) return;
        if(head.next == null) return;
        if(head.next.next == null) return;
        ListNode second = head.next;
        ListNode tail = head.next.next;
        ListNode pre = head.next;
        while(tail.next != null){
            pre = tail;
            tail = tail.next;
        }
        pre.next = null;
        head.next = tail;
        tail.next = second;
        reorderList(second);
    }
}