合并链表

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;
}
};

最新文章

  1. HTML5 语义元素(一)页面结构
  2. 事后分析报告(Postmortem Report)
  3. 终端改变host的类型,还原
  4. 30. Distinct Subsequences
  5. 在meteor中使用支付,以及与服务器进行数据交互
  6. B-tree解释
  7. JS模块化规范CommonJS,AMD,CMD
  8. java后台开发- NOTE
  9. Do not wait until the conditions are perfect to begin. Beginning makes the conditions perfect(转)
  10. 01-编写CMS注意事项
  11. MyEclipse 2015 如何使项目能够使用 Hibernate自动生成文件
  12. Java集合常见面试题集锦
  13. linux ubuntu 远程ssh登录
  14. windows 基础命令小集
  15. Netty返回数据丢包的问题之一
  16. Java学习——包及可见性
  17. LINQ中in的实现方法-LINQ To Entities如何实现查询 select * from tableA where id in (1,2,3,4)
  18. 背景 半透明问题 rgba + filter
  19. Buff系统的实现
  20. oracle中job定时器任务

热门文章

  1. 开源项目 RethinkDB 关闭,创始人总结失败教训(市场定位错误)
  2. IT++数学、信号、通讯类库,Blitz++数学,Armadillo 线性代数,Dlib网络,线程,图形,数学,图像,数据挖掘/机器学习,XML等等
  3. VS使用的快捷方式
  4. Java基础(二) 基本类型数据类型、包装类及自动拆装箱
  5. Java算法-求最大和的子数组序列
  6. Scala 学习之路(九)—— 继承和特质
  7. MAC subline批处理
  8. linux 安装 websocketd
  9. BZOJ 2460:元素(贪心+线性基)
  10. 01(b)无约束优化(准备知识)