Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
package pack;
class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
if(l1 == null)
return l2;
if(l2 == null)

这篇博客探讨了如何将两个已排序的链表合并为一个新的有序链表。通过连接这两个链表的节点,可以创建出合并后的列表。
订阅专栏 解锁全文
1464

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



