/**
* 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. 基于Web和二维码的文件传输服务

    在工作中难免需要对外提供一些我们抓取的log或者操作视频之类的资料,但由于工作环境日渐规范和严格,公司的网络环境和客户的网络环境是被独立开来的.这样做的好处不必多说,但同时也给我们工作带来的诸多不便. ...

  2. Powershell调用RemoteExchange.ps1

    If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010" ...

  3. Unix file types

    w https://en.wikipedia.org/wiki/Unix_file_types A socket is a special file used for inter-process co ...

  4. 传说中的MATLAB1.0(1984年DOS界面182K、运行良好)附下载

    传说中的MATLAB1.0(1984年DOS界面182K.运行良好)附下载 你见过 MATLAB 最早的版本吗?下载一份 MATLAB 1.0,(只有182K, 只有20来个函数) 体会一下吧.MAT ...

  5. 原!findbugs:NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE 和 OBL_UNSATISFIED_OBLIGATION

    改findbogs碰到的两个问题,一个是关于IO流,一个是关于空指针检查异常. 1.NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE 前面代码略... File crFil ...

  6. Linux学习笔记(13)linux软件安装rpm与yum--理论篇

    该文章linux知识点如下 1.linux中 软件包介绍 2.linux源码软件安装 3.linux二进制软件安装 4.linux rpm软件包管理 5.linux yum软件包管理 1.linux中 ...

  7. C语言自带快速排序对比插入排序

    #include <stdio.h> #include <stdlib.h> #include <time.h> void getRandomArr (int ar ...

  8. maven项目打WAR包记录

    打了个war包,各种不顺,也是以前没打过的原因,眼高手低了…… cmd 进入项目目录 打开 运行----cmd 进入命令窗口 键入 cd 回车 输入E\:mars\cdc 键入 mvn clean p ...

  9. 练T25- focus必看!所有成功截图汇总

    http://www.guokr.com/post/565880/ 25914人加入此小组 发新帖 练T25- focus必看!所有成功截图汇总! 读图模式 作家向威 作家 2014-02-22 07 ...

  10. 美国评出2016最值得去的旅游胜地+纯电动车郊游记+DIY一个小电动车

    美国评出2016最值得去的旅游胜地(10) http://bbs.miercn.com/bd/201510/thread_569397_1_10.html 自带发电机! 北汽E150 EV纯电动车郊游 ...