public ListNode sortList(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode p1 = head, p2 = head;
        while(p2.next != null && p2.next.next != null) {
            p2 = p2.next.next;
            p1 = p1.next;
        }
        p2 = p1.next;
        p1.next = null;
        ListNode left = sortList(head);
        ListNode right = sortList(p2);
        return merge(left, right);
    }