题目在这里: 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. c语言实现灰度图转换为二值图

    将上篇得到的灰度图转换为二值图,读取像素数据,低于某一值置0,否则设置为255,为得到更好的效果不同图片应采用不同的值 /* 2015年6月2日11:16:22 灰度图转换为二值图 blog:http ...

  2. d3可视化实战03:神奇的superformula

    需求驱动实现 前文讲过了D3的数据驱动机制,中间所举的例子都很简单.例如那个demo里面,绑定的数据是一个简单的数组,实现的图元也仅仅是一堆用SVG画的circle.但是现实世界中我们往往会遇到复杂的 ...

  3. 使用jsoup解析html页面内容案例

    public String getFaGuiKuTitles(String type, int page) { String href = "http://info.qd-n-tax.gov ...

  4. Android json操作之取得一个对象

    1:服务端返回的json数据格式如下: {"id":"1001","name":"zhangsan","sco ...

  5. ural 1090 In the Army Now

    http://acm.timus.ru/problem.aspx?space=1&num=1090 #include <cstdio> #include <cstring&g ...

  6. C++面试问题总结

    转自:http://blog.csdn.net/wangtengqiang/article/details/8061806 1.static用法 static 的成员函数和成员变量,可直接通过类名:: ...

  7. MCS-51单片机的指令时序

    时序是用定时单位来描述的,MCS-51的时序单位有四个,它们分别是节拍.状态.机器周期和指令周期,接下来我们分别加以说明. 节拍与状态:    我们把振荡脉冲的周期定义为节拍(为方便描述,用P表示), ...

  8. C 語言中的編譯指示 (Pragma)

    編譯指示 #pragma 是用來告知編譯器某些特殊指示,例如不要輸出錯誤訊息,抑制警告訊息,或者加上記憶體漏洞檢查機制等.這些指示通常不是標準的 C 語言所具備的,而是各家編譯器廠商或開發者所制定的, ...

  9. 基于SQL_ID查看对象大小

    SQL> set echo off set echo off set verify off set serveroutput on set feedback off set lines 200 ...

  10. HDU_2051——十进制到二进制转换

    Problem Description Give you a number on base ten,you should output it on base two.(0 < n < 10 ...