[leetcode] 21. Merge Two Sorted Lists (Easy)
合并链表
Runtime: 4 ms, faster than 100.00% of C++ online submissions for Merge Two Sorted Lists.
class Solution
{
public:
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2)
{ //1 2 4 . 1 3 4
ListNode *res = new ListNode();
ListNode *cur = res;
while (l1 != NULL && l2 != NULL)
{
if (l1->val <= l2->val)
{
cur->next = l1;
l1 = l1->next;
cur = cur->next;
}
else
{
cur->next = l2;
l2 = l2->next;
cur = cur->next;
}
}
if (l1 != NULL)
cur->next = l1;
else
cur->next = l2;
return res->next;
}
};
[leetcode] 21. Merge Two Sorted Lists (Easy)的更多相关文章
- [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] 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 21. Merge Two Sorted Lists(easy)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- # 蜗牛慢慢爬 LeetCode 21. Merge Two Sorted Lists [Difficulty: Easy]
题目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...
- 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 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 ...
- Java [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 spli ...
- [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 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 ...
随机推荐
- CSS3 GENERATOR可以同时为一个元素完成border-radius、box-shadow、gradient和opacity多项属性的设置
CSS3 GENERATOR可以同时为一个元素完成border-radius.box-shadow.gradient和opacity多项属性的设置 CSS3 GENERATOR 彩蛋爆料直击现场 CS ...
- Realm_King 之 .NET 打包详细教程(A)
最近一直在winform程序开发,听说身边的人不是很了解打包,给大家提供一点简单的打包,相信能看懂的... (一)右键解决方案: 在弹出"添加新项目"窗体中找到 其他项目类型=& ...
- 2013年最流行的php框架盘点
2013年最流行的php框架盘点 PHP框架的发展背景 毫无疑问,Web框架技术在近几年已经得到了突飞猛进的发展和普及,在过去几年里,框架技术的普遍经历了比较大的完善过程,很大一部分可以归因于Ruby ...
- java多线程之生产者-消费者
public class Product { private String lock; public Product(String lock) { this.lock = lock; } public ...
- 简单看看jdk7源码之java.lang包01
从今天开始简单开始读一遍jdk的源码,估计这个时间会很长,慢慢啃吧....(首先说一句抱歉,因为很多图都是直接百度扣的,图太多了不能为每一个图附上原版链接,不好意思!) 在网上看了很多的教程,读源码有 ...
- 高并发 Nginx+Lua OpenResty系列(7)——Lua开发库json
JSON库 在进行数据传输时JSON格式目前应用广泛,因此从Lua对象与JSON字符串之间相互转换是一个非常常见的功能:目前Lua也有几个JSON库,如:cjson.dkjson.其中cjson的语法 ...
- 自定义实现一个loghub(或kafka)的动态分片消费者负载均衡?
一般地,像kafka之类的消息中间件,作为一个可以保持历史消息的组件,其消费模型一般是主动拉取方式.这是为了给消费者足够的自由,回滚或者前进. 然而,也正是由于将消费消息的权力交给了消费者,所以,消费 ...
- 移动端使用rem.js,解决rem.js 行内元素占位问题
父级元素: letter-spacing: -0.5em;font-size: 0; 子级元素: letter-spacing: normal; display: inline-block; vert ...
- 使用Visual Studio Code进行MicroPython编程
转载请注明文章来源,更多教程可自助参考docs.tpyboard.com,QQ技术交流群:157816561,公众号:MicroPython玩家汇 Visual Studio Code(以下简称VSC ...
- Spring Environment抽象
1:概述 Spring中Environment是Spring3.1版本引入的,是Spring核心框架定义的一个接口,用来表示整个应用运行时环境.该环境模型只接受两种应用环境profiles(配置文件) ...