/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
struct ListNode* root=NULL;
if(!list1) return list2;
if(!list2) return list1;
if(list1->val<list2->val){
root=list1;
root->next=mergeTwoLists(list1->next,list2);
}else{
root=list2;
root->next=mergeTwoLists(list1,list2->next);
}
return root;
}
结果:
标签:ListNode,21,list1,list2,链表,有序,next,root,struct From: https://www.cnblogs.com/llllmz/p/18076115