2021年9月8日10:20:43
2021年9月8日10:29:08

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class Solution {
    public ListNode Merge(ListNode list1,ListNode list2) {
        ListNode cur1 = list1;
        ListNode cur2 = list2;
        ListNode newhead = new ListNode(-1);
        ListNode cur = newhead;

        while(cur1 != null && cur2 != null){
            if(cur1.val > cur2.val){
                cur.next = new ListNode(cur2.val);
                cur2 = cur2.next;
            }
            else{
                cur.next = new ListNode(cur1.val);
                cur1 = cur1.next;
            }
            cur = cur.next;
        }
        while(cur1 != null) {
            cur.next = new ListNode(cur1.val);
            cur1 = cur1.next;
            cur = cur.next;
        }
        while(cur2 != null) {
            cur.next = new ListNode(cur2.val);
            cur2 = cur2.next;
            cur = cur.next;
        }

        return newhead.next;
    }
}