public ListNode Merge(ListNode list1,ListNode list2) {
if(list1 == null || list2 == null){
return list1 = (list1 != null ? list1 : list2);
}
ListNode newNode;
if(list1.val > list2.val){
newNode = list2;
newNode.next = Merge(list2.next, list1);
}else{
newNode = list1;
newNode.next = Merge(list1.next, list2);
}
return newNode;
}
25 合并两个排序的链表
最新推荐文章于 2024-09-28 15:47:39 发布
本文探讨如何高效地合并两个已排序的链表,通过递归和迭代两种方法实现,详细解析每种方法的步骤,并分析它们的时间复杂度。
579

被折叠的 条评论
为什么被折叠?



