21. 合并两个有序链表
作者:互联网
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
if(list1 == null){
return list2;
}
if(list2 == null){
return list1;
}
ListNode res = list1.val < list2.val ? list1 : list2;
res.next = mergeTwoLists(res.next, list1.val >= list2.val ? list1 : list2);
return res;
}
}
标签:ListNode,21,val,res,list1,list2,链表,有序,return 来源: https://www.cnblogs.com/my-blog-site/p/16273068.html