class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
if(l1 == null) return l2;
if(l2 == null) return l1;
ListNode head = l1.val < l2.val ? l1 : l2;
head.next = mergeTwoLists(head.next, head == l1 ? l2 : l1);
return head;
}
}
LeetCode热题Hot-20 合并两个有序链表
最新推荐文章于 2024-08-04 15:31:19 发布