public ListNode sortList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode fast = head, slow = head;
        while (fast.next != null && fast.next.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        ListNode left = head, right = slow.next;
        slow.next = null;
        left = sortList(left);
        right = sortList(right);
        ListNode cur = head = new ListNode(-1);
        while (left != null && right != null) {
            if (left.val <= right.val) {
                cur.next = left;
                left = left.next;
            } else {
                cur.next = right;
                right = right.next;
            }
            cur = cur.next;
        }
        while (left != null) {
            cur.next = left;
            cur = left;
            left = left.next;
        }
        while (right != null) {
            cur.next = right;
            cur = right;
            right = right.next;
        }
        return head.next;
    }