/*
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 dummyhead=new ListNode(-1);
ListNode last=dummyhead;
if(list1==null)
{return list2;}
if(list2==null){
return list1;
}
while(list1!=null&&list2!=null)
{
if(list1.val<=list2.val)
{
last.next=list1;
last=list1;
list1=list1.next;
}else{
last.next=list2;
last=list2;
list2=list2.next;
}
if(list1==null)
{last.next=list2;}
if(list2==null)
{last.next=list1;}
}return dummyhead.next;
}
}
/*
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 dummyhead=new ListNode(-1);
ListNode last=dummyhead;
if(list1==null)
{return list2;}
if(list2==null){
return list1;
}
while(list1!=null&&list2!=null)
{
if(list1.val<=list2.val)
{
last.next=list1;
last=list1;
list1=list1.next;
}else{
last.next=list2;
last=list2;
list2=list2.next;
}
}return dummyhead.next;
}
}
`/*
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 dummyhead=new ListNode(-1);
ListNode last=dummyhead;
if(list1==null)
{return list2;}
if(list2==null){
return list1;
}
while(list1!=null&&list2!=null)
{
if(list1.val<=list2.val)
{
last.next=list1;
last=list1;
list1=list1.next;
}else{
last.next=list2;
last=list2;
list2=list2.next;
}
if(list1==null)
{last.next=list2;}
if(list2==null)
{last.next=list1;}
}return dummyhead.next;
}
}
`