/**
* 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 dumy = new ListNode(0);
ListNode head = dumy;
while(l1 != null && l2 != null)
{
if(l1.val < l2.val)
{
dumy.next = l1;
l1 = l1.next;
}
else
{
dumy.next = l2;
l2 = l2.next;
}
dumy = dumy.next;
}
if(l1 == null)
{
dumy.next = l2;
}
if(l2 == null)
{
dumy.next = l1;
}
return head.next;
}
}

merge two sorted lists, 合并两个有序序列的更多相关文章

  1. 【LeetCode】21. Merge Two Sorted Lists 合并两个有序链表

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:合并,有序链表,递归,迭代,题解,leetcode, 力 ...

  2. leetcode 21 Merge Two Sorted Lists 合并两个有序链表

    描述: 合并两个有序链表. 解决: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if (!l1) return l2; if (!l2) ...

  3. LeetCode 21. Merge Two Sorted Lists合并两个有序链表 (C++)

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

  4. [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 ...

  5. 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 t ...

  6. 【LeetCode】Merge Two Sorted Lists(合并两个有序链表)

    这道题是LeetCode里的第21道题. 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1-&g ...

  7. [LeetCode] Merge k Sorted Lists 合并k个有序链表

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

  8. [LeetCode] 23. Merge k Sorted Lists 合并k个有序链表

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

  9. 21. Merge Two Sorted Lists(合并2个有序链表)

    21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list s ...

  10. [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 ...

随机推荐

  1. 如何修改Myeclipse的JSP模板

    先找到MyEclipse的安装目录, 再找到myeclipse/eclipse/plugins/com.genuitec.eclipse.wizards_5.1.0/templates/jsp (co ...

  2. The Log: What every software engineer should know about real-time data's unifying abstraction

    http://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-abo ...

  3. IO流入门-第五章-FileWriter

    FileWriter基本用法和方法示例 /* java.io.Writer java.io.OutputStreamWriter 转换流(字节输出流--->字符输出流) java.io.File ...

  4. Python SQLAlchemy基本操作和常用技巧(包含大量实例,非常好)

    https://www.jb51.net/article/49789.htm 首先说下,由于最新的 0.8 版还是开发版本,因此我使用的是 0.79 版,API 也许会有些不同.因为我是搭配 MySQ ...

  5. 在.NET中读取嵌入和使用资源文件的方法

    转http://www.jb51.net/article/84660.htm 本文分别介绍了使用GetManifestResourceStream读取嵌入资源,和使用. resx资源文件嵌入资源,希望 ...

  6. mysql分组取每组前几条记录(排名)

    1.创建表 create table tb( name varchar(10), val int, memo varchar(20) ); 2.插入数据 insert into tb values(' ...

  7. CNN结构

    神经网络 卷积神经网络依旧是层级网络,只是层的功能和形式做了变化,可以说是传统神经网络的一个改进.多了许多传统神经网络没有的层次. 卷积神经网络的层级结构 数据输入层/Input Layer 卷积计算 ...

  8. Linux学习笔记(8)文件搜索与帮助

    帮助: (1) man ls (2) info  ls  (3) whatis ls  (4) help 搜索: (1) which  ls :查看ls命令所在绝对路径 (2) locate user ...

  9. 使用Xcode改动iOS项目project名和路径名

    对,好.错.改正. ------ 前言 系统 10.9 开发平台 xcode 5.0 旧project名 MyProject-iPad 改动之后 新project名 FjSk-iPad 点击项目,进入 ...

  10. Eclipse插件--一次copy多个文件的相对路径路径

    因为工作需要, 在网上找了很多插件, 本来有个easyTools应该可以, 但下载文件好像没了. 只好自己动手搞了一个简单的, 暂时一个复制文件相对路径的功能, 有同样需求的童鞋, 可以试一下 plu ...