public void reorderList(ListNode head) {
        if (head == null || head.next == null || head.next.next == null)
            return;
        int len = 0;
        ListNode fast = head, slow = head, ptr = new ListNode(-1);
        ptr.next = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            ptr = ptr.next;
        }
        // reverse linked list
        ListNode node = ptr;
        while (slow != null) {
            ListNode temp = slow.next;
            slow.next = ptr;
            ptr = slow;
            slow = temp;
        }
        node.next.next = null;
        node.next = null;
        slow = ptr;
        ptr = head;

        while (ptr != null && slow != null) {
            ListNode temp1 = ptr.next;
            ListNode temp2 = slow.next;
            ptr.next = slow;
            if (temp1 != null)
                slow.next = temp1;
            slow = temp2;
            ptr = temp1;
        }
    }