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.
这里sorted说的是从小到大。
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode ln = new ListNode(

本文介绍如何将两个已排序的链表合并成一个新的有序链表。通过插入排序的方法,将节点逐一合并,形成新的有序链表。
订阅专栏 解锁全文
411

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



