[leetcode] 21. Merge Two Sorted Lists (Easy)
2024-08-31 20:19:15
合并链表
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;
}
};
最新文章
- HTML5 语义元素(一)页面结构
- 事后分析报告(Postmortem Report)
- 终端改变host的类型,还原
- 30. Distinct Subsequences
- 在meteor中使用支付,以及与服务器进行数据交互
- B-tree解释
- JS模块化规范CommonJS,AMD,CMD
- java后台开发- NOTE
- Do not wait until the conditions are perfect to begin. Beginning makes the conditions perfect(转)
- 01-编写CMS注意事项
- MyEclipse 2015 如何使项目能够使用 Hibernate自动生成文件
- Java集合常见面试题集锦
- linux ubuntu 远程ssh登录
- windows 基础命令小集
- Netty返回数据丢包的问题之一
- Java学习——包及可见性
- LINQ中in的实现方法-LINQ To Entities如何实现查询 select * from tableA where id in (1,2,3,4)
- 背景 半透明问题 rgba + filter
- Buff系统的实现
- oracle中job定时器任务
热门文章
- 开源项目 RethinkDB 关闭,创始人总结失败教训(市场定位错误)
- IT++数学、信号、通讯类库,Blitz++数学,Armadillo 线性代数,Dlib网络,线程,图形,数学,图像,数据挖掘/机器学习,XML等等
- VS使用的快捷方式
- Java基础(二) 基本类型数据类型、包装类及自动拆装箱
- Java算法-求最大和的子数组序列
- Scala 学习之路(九)—— 继承和特质
- MAC subline批处理
- linux 安装 websocketd
- BZOJ 2460:元素(贪心+线性基)
- 01(b)无约束优化(准备知识)