merge-two-sorted-lists合并链表
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.
合并两个有序链表
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
ListNode *head=new ListNode();
ListNode *t=head;
while(l1!=NULL && l2!=NULL)
{
if(l1->val<l2->val)
{
t->next=l1;
l1=l1->next;
}else{
t->next=l2;
l2=l2->next;
}
t =t->next;
}
if(l1!=NULL)
t->next=l1;
if(l2!=NULL)
t->next=l2;
return head->next;
}
};
merge-two-sorted-lists合并链表的更多相关文章
- [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 ...
- [LeetCode] Merge k Sorted Lists 合并k个有序链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这 ...
- [Leetcode] Merge k sorted lists 合并k个已排序的链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思 ...
- [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 ...
- 【LeetCode】21. Merge Two Sorted Lists 合并两个有序链表
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:合并,有序链表,递归,迭代,题解,leetcode, 力 ...
- 【LeetCode】23. Merge k Sorted Lists 合并K个升序链表
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:合并,链表,单链表,题解,leetcode, 力扣,Py ...
- 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 ...
- [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 ...
- 【LeetCode每天一题】 Merge k Sorted Lists(合并K个有序链表)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. E ...
- [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 ...
随机推荐
- mariadb 重置密码
1. sudo身份打开 /etc/mysql/my.cnf 在[mysqld]节点下增加如下代码: skip-grant-tables #忽略密码授权 2. 杀掉mysql进程,重启mariadb,这 ...
- 【转】Android思维导图
转自:http://www.open-open.com/lib/view/open1421201191375.html
- 最常使用Eclipse快捷键
一:编辑 alt+/:智能感知: alt+shift+s:出现代码块: ctrl+1:quick fix,同时还有简单的重构功能: ctrl+e:快速转换编辑器 ,这组快捷键将帮助你在打开的编辑器之间 ...
- Visual Studio 2013 智能提示功能消失解决办法
Visual Studio 2013中,智能提示功能突然用不了,查了一下,使用命令行重置VS的方法解决了这个问题.步骤如下: 开始菜单 -->所有程序-->Visual Studio 20 ...
- [转]CENTOS LINUX安装并使用NFS共享文件
FROM :http://www.qiansw.com/centos-linux-nfs.html NFS是linux常用的一种文件分享工具. 下面介绍安装及使用方法. CentOS 5.5 yum ...
- ASP.NET Core 中间件 中间件(Middleware)和过滤器(Filter)的区别
https://www.cnblogs.com/savorboard/p/5586229.html 前言 在上篇文章主要介绍了DotNetCore项目状况,本篇文章是我们在开发自己的项目中实际使用的, ...
- Centos 7安装protobuf3.6.1
新版本 google protobuf-3.6.1是现在最新版本,添加了新的特性,看说明 下载地址 https://github.com/protocolbuffers/protobuf/releas ...
- 构造读写IRP(转)
DDK示例中的代码. NTSTATUSFltReadSectors( IN PDEVICE_OBJECT DeviceObject, OUT PVOID Buffer, IN ULONG Len ...
- 用C#进行DirectX开发
DirectX 9.0 的Manage DirectX部分包括下列九个程序集. Microsoft.DirectX.AudioVideoPlayback.dll Microsoft.DirectX.D ...
- VC++深入详解-第四章学习心得
这一章节主要讲解了 简单的绘图 主要是通过一些小的例子让我们学会了VC++的一些基本操作 void CDrawView::OnLButtonDown(UINT nFlags, CPoint point ...