[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 ...
随机推荐
- 学在LINUX下编程(各种情况比较详细)
(from http://www.712100.com/bbs/redirect.php?fid=160&tid=191752&goto=nextnewset) 预备知识 用gcc ...
- [收录] Highcharts-ng —— AngularJS 的图表扩展
原文:http://www.tuicool.com/articles/u6VZJjQ Highcharts-ng 是一个 AngularJS 的指令扩展,实现了在AngularJS 应用中集成High ...
- 修改Maven的本地仓库地址
已经配置好的设定文件: 1.创建一个本地仓库的地址 2.修改Maven中conf目录下的settings.xml文件 在此处添加修改后的本地仓库的地址 3.打开cmd 输入mvn help:sys ...
- 在Qt工程中加Boost
摘要: Boost是一个很强大的C++库,堪比STL,里面有很多非常优秀的类库.我不多介绍,详情见官网:http://www.boost.org/ 要在我们的Qt工程中把这个库加进去应该怎么做呢?我今 ...
- UTM (Urchin Tracking Module) codes
UTM Codes are a great way to see the results of your offline marketing In today’s day and age, we ar ...
- Java虚拟机详解(二)------运行时内存结构
首先通过一张图了解 Java程序的执行流程: 我们编写好的Java源代码程序,通过Java编译器javac编译成Java虚拟机识别的class文件(字节码文件),然后由 JVM 中的类加载器加载编译生 ...
- Ruby字符串(2):String方法详细整理
String方法整理 官方手册 类方法 new new(str="") → new_str new(str="", encoding: enc) → new_s ...
- mount -- 挂载理解
1.挂载? 在windows操作系统中, 挂载通常是指给磁盘分区(包括被虚拟出来的磁盘分区)分配一个盘符. 第三方软件,如磁盘分区管理软件.虚拟磁盘软件等,通常也附带挂载功能. 在linux操作系统中 ...
- Effective Java - 构造器私有、枚举和单例
目录 饿汉式单例 静态常量 静态代码块 懒汉式单例 尝试加锁 同步代码块 双重检查 静态内部类单例 枚举单例 Singleton 是指仅仅被实例化一次的类.Singleton代表了无状态的对象像是方法 ...
- 关于elasticsearch安装及搭建集群时候的错误
1,在Windows上解压后启动elasticsearch后可能cmd中会抛出java 无法初始话异常,网上查询必须用的是jdk1.8以上,可是本人用的 就是jdk1.8啊,半天解决无果,最后重新安装 ...