两个升序链表的合并 Merge Two Sorted Lists 【 leetcode】
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
ListNode *p;
ListNode *p1=p;
while(l1!=NULL && l2!=NULL){
if((l1->val)<(l2->val)){
p->next=l1;
p=p->next;
l1=l1->next;
}
else{
p->next=l2;
p=p->next;
l2=l2->next;
}
}
if(!l1) p->next=l2;
if(l2==NULL) p->next=l1;
return p1->next;
}
};
两个升序链表的合并 Merge Two Sorted Lists 【 leetcode】的更多相关文章
- Merge Two Sorted Lists - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Merge Two Sorted Lists - LeetCode 注意点 两个链表长度可能不一致 解法 解法一:先比较两个链表长度一致的部分,多余的部分 ...
- 23. Merge k Sorted Lists - LeetCode
Question 23. Merge k Sorted Lists Solution 题目大意:合并链表数组(每个链表中的元素是有序的),要求合并后的链表也是有序的 思路:遍历链表数组,每次取最小节点 ...
- 链表经典题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 ...
- Merge Two Sorted Lists—LeetCode
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- Merge k Sorted Lists Leetcode Java
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 使 ...
- Merge Two Sorted Lists leetcode java
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- Merge k Sorted Lists [LeetCode]
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. S ...
- 蜗牛慢慢爬 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 ...
- LeetCode 21. 合并两个有序链表(Merge Two Sorted Lists)
21. 合并两个有序链表 21. Merge Two Sorted Lists 题目描述 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. LeetCode ...
随机推荐
- mysql学习笔记——支持存储引擎
- jquery对于table的操作
$("#datable tr").eq(0).children("td").eq(0).html() //获得某行某列的值
- [BS-15] Values of type 'NSInteger' should not be used as format arguments
Values of type 'NSInteger' should not be used as format arguments 苹果app支持arm64以后会有一个问题:NSInteger变成64 ...
- 3、DOM操作
一.认识DOM 文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 先来看看下面 ...
- 维护计划生成的SSIS包存储在哪
首先理解导入导出包的基本概念:http://technet.microsoft.com/zh-cn/library/ms141772(v=SQL.110).aspx包既可以保存在SQL Server ...
- IDisplayTransformation
IDisplayTransformation Bounds Full extent in world coordinates. The Bounds property controls the ful ...
- 轻量级的jquery
话不多说,直接上源代码 一.tool.js 封装一些共用方法,以及相关的浏览器兼容细节,供Base.js调用 //浏览器检测,一旦加载即执行 (function() { window.sys = {} ...
- 安装和删除 Alcatraz 插件
在终端下输入如下命令来安装Alcatraz: curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install. ...
- MVC4之ModelBinder-模型绑定
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 最近在做自学MVC,遇到的问题很多,索性一点点总结 ...
- openSuSE DNS SERVER CONFIG
system:openSuSE 12.3(much better and frendly than the 12.1 in network config)1,network config,attent ...