public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode Merge(ListNode list1,ListNode list2) {
if(list1 == null ){
return list2;
}
if(list2 == null){
return list1;
}
ListNode head = new ListNode(-1);
ListNode current = head;
ListNode cur1 = list1;
ListNode cur2 = list2;
while(cur1!=null && cur2 != null){
if(cur1.val > cur2.val){
current.next = cur2;
current = cur2;
cur2 = cur2.next;
}else{
current.next = cur1;
current = cur1;
cur1 = cur1.next;
}
}
if(cur1 == null){
current.next = cur2;
}
if(cur2 == null){
current.next = cur1;
}
return head.next;
}
}