/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {
struct ListNode* newhead=NULL;
if(NULL==l1){
return l2;
}else if(NULL==l2){
return l1;
}else{
if(l1->val<l2->val){
newhead=l1;
newhead->next=mergeTwoLists(l1->next,l2);
}else{
newhead=l2;
newhead->next=mergeTwoLists(l2->next,l1);
}
return newhead;
}
}
21. 合并两个有序链表
最新推荐文章于 2024-05-04 09:47:06 发布