public static ListNode mergeSortedList(ListNode head1, ListNode head2) {
        if (head1 == null) {
            return head2;
        }
        if (head2 == null) {
            return head1;
        }
        ListNode retNode = null;
        if (head1.val < head2.val) {
            retNode = head1;
            retNode.next = null;
            head1 = head1.next;
        } else {
            retNode = head2;
            retNode.next = null;
            head2 = head2.next;
        }
        ListNode curNode = retNode;
        while (head1 != null && head2 != null) {
            if (head1.val < head2.val) {
                curNode.next = head1;
                head1 = head1.next;
                curNode = curNode.next;
                curNode.next = null;
            } else {
                curNode.next = head2;
                head2 = head2.next;
                curNode = curNode.next;
                curNode.next = null;
            }
        }

        if (head1 != null) {
            curNode.next = head1;
        } else {
            curNode.next = head2;
        }
        return retNode;
    }