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 ...
随机推荐
- CSS 强制换行和禁止换行强制换行 和禁止换行样式
强制换行 1.word-break: break-all; 只对英文起作用,以字母作为换行依据. 2.word-wrap: break-word; 只对英文起作用,以单词作为换行依据. ...
- jQuery的deferred对象详解 jquery回调函数
http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html jQuery的 ...
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.h
DA就是“Denoising Autoencoders”的缩写.继续给yusugomori做注释,边注释边学习.看了一些DA的材料,基本上都在前面“转载”了.学习中间总有个疑问:DA和RBM到底啥区别 ...
- 阿里jstorm和storm区别
转自:https://www.cnblogs.com/cn-leodream/p/6497277.html 看介绍文档貌似挺好:https://github.com/alibaba/jstorm ...
- iOS开发调试篇—Print Description of "string"
Print Description of "string":把 string 的信息输出到控制台.Copy:复制 string 的信息,包含变量名,类名和值.View Value ...
- Logistic Regression总结
转自:http://blog.csdn.net/dongtingzhizi/article/details/15962797 Logistic回归总结 作者:洞庭之子 微博:洞庭之子-Bing (20 ...
- 学习笔记:Maven的ArcheType的学习笔记
摘要: Archetype是什么?它由哪些文件组成?如何创建和安装自己的archtype,如何使用自己创建的archetype? 一.Archetype是什么 Archetype其实就 ...
- PowerDesigner设置表字段唯一约束
现有一个表student,id为主键. 现打算给name添加一个唯一约束. 双击打开这个表,点击“keys"选项卡,显示有一个key_1,这是id主键. 点击”insert a row'插入 ...
- JAVA-jar包下载地址
spring mvc常用jar包 commons-logging:http://commons.apache.org/proper/commons-logging/download_logging.c ...
- linux下性能分析命令[总结]
1.前言 在linux下开发程序,为了追求高性能,经常需要测试程序的性能,包括cpu.内存.io.网络等等使用情况.liunx下提供了众多命令方便查看各种资源的使用情况.经常用的有ps.top.fre ...