题目在这里: https://leetcode.com/problems/merge-two-sorted-lists/

【标签】Linked List

【题目分析】这个题目就是merge sort在 Linked List中的变形。不多说,直接上代码了

   public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode dummyHead = new ListNode(-1);
ListNode node = dummyHead;
while (l1 != null && l2 != null) {
if (l1.val <= l2.val) {
node.next = l1;
l1 = l1.next;
} else {
node.next = l2;
l2 = l2.next;
}
node = node.next;
}
// append the remaining list
node.next = (l1 != null) ? l1 : l2;
return dummyHead.next;
17  }

[Leetcode][021] Merge Two Sorted Lists (Java)的更多相关文章

  1. 【JAVA、C++】LeetCode 021 Merge Two Sorted Lists

      Merge two sorted linked lists and return it as a new list. The new list should be made by splicing ...

  2. Leetcode 021 Merge Two Sorted Lists

    摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...

  3. leetcode 21.Merge Two Sorted Lists ,java

    题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  4. Java for LeetCode 023 Merge k Sorted Lists

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解 ...

  5. [LeetCode] 21. Merge Two Sorted Lists 合并有序链表

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  6. 蜗牛慢慢爬 LeetCode 23. Merge k Sorted Lists [Difficulty: Hard]

    题目 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity ...

  7. [LeetCode] 21. Merge Two Sorted Lists 混合插入有序链表

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  8. LeetCode 23 Merge k Sorted Lists(合并k个有序链表)

    题目链接: https://leetcode.com/problems/merge-k-sorted-lists/?tab=Description Problem: 给出k个有序的list, 将其进行 ...

  9. [Leetcode Week4]Merge Two Sorted Lists

    Merge Two Sorted Lists题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/merge-two-sorted-lists/descrip ...

随机推荐

  1. HTML5+Css3-webkit-filter

    -webkit-filter 现在规范中支持的效果有: grayscale 灰度 sepia 褐色 saturate 饱和度 hue-rotate 色相旋转 invert 反色 opacity 透明度 ...

  2. [POJ] 3020 Antenna Placement(二分图最大匹配)

    题目地址:http://poj.org/problem?id=3020 输入一个字符矩阵,'*'可行,'o'不可行.因为一个点可以和上下左右四个方向的一个可行点组成一个集合,所以对图进行黑白染色(每个 ...

  3. 解决Android ListView 和 ScrollView 共存时冲突 问题 方法其一

    转载请注明出处: http://www.goteny.com/articles/2013/11/8.html http://www.cnblogs.com/zjjne/p/3428480.html 当 ...

  4. 禁用USB存储设备(不重启)

    Title:禁用USB存储设备(不重启) -- 2012-09-13 12:08 在win2003实验,USB存储禁止,无需重启! stop usbrw.reg ------------------- ...

  5. KesionCMS V6.5后台拿SHELL方法

    Title:KesionCMS V6.5后台拿SHELL方法  --2011-03-29 00:21 最近弄一个站点,是KesionCMS V6.5的WEB系统,试了下后台拿webshell方法,记下 ...

  6. USB 0xC0000012 错误详解

    0xC0000012Bus Hound 6.01 capture on Windows Vista Service Pack 1 (x86). Complements of www.perisoft. ...

  7. Altium Designer6打印PCB转印纸设置方法

    在学校经常要用热转印法做一些简单的PCB板,自己用的AD6.6,学校的打印店用99的比较多,这就造成打印不方便.为了充分利用自己实验室的打印机,今天买回来两张PCB打印纸.发现用AD6打印同比例的PC ...

  8. VCC、VDD、VEE、VSS

    转载自:http://www.cnblogs.com/asus119/archive/2011/10/11/2206841.html 版本一: 简单说来,可以这样理解: 一.解释 VCC:C=circ ...

  9. DACL, NULL or not NULL

    上周 hBifTs在折腾他的文件映射封装类的时候,碰到了不能在 ASP.NET 中直接打开由桌面程序创建的内核对象的问题. 内存映射文件与用户权限 他当时是的方法是修改 ASP.NET 配置文件,让 ...

  10. Changing a Service's Configuration

    Changing a Service's Configuration   A service configuration program uses the ChangeServiceConfig an ...