Leetcode--Merge Two Sorted Lists
static ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
ListNode *temp = );
ListNode *head = temp;
if (l1 == NULL && l2 == NULL)
return head;
while (l1 != NULL && l2 != NULL) {
if (l1->val <= l2->val) {
temp->next = new ListNode(l1->val);
temp = temp->next;
l1 = l1->next;
} else {
temp->next = new ListNode(l2->val);
temp = temp->next;
l2 = l2->next;
}
}
if (l1 == NULL && l2 != NULL)
temp->next = l2;
else if (l2 == NULL && l1 != NULL)
temp->next = l1;
return head->next;
}
Leetcode--Merge Two Sorted Lists的更多相关文章
- [LeetCode] Merge k Sorted Lists 合并k个有序链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这 ...
- [LeetCode] 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: Merge Two Sorted Lists 解题报告
Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list shoul ...
- LeetCode: Merge k Sorted Lists 解题报告
Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and descr ...
- [Leetcode] Merge k sorted lists 合并k个已排序的链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思 ...
- LeetCode:Merge k Sorted Lists
题目链接 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexi ...
- LeetCode——Merge k Sorted Lists
Discription: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its ...
- leetcode: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 -- Merge k Sorted Lists add code
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. [ ...
- LeetCode Merge k Sorted Lists (链表)
题意 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity ...
随机推荐
- Redmine自定义字段增多后会变慢
问题: 在Redmine部署使用后,发现更新事务时速度慢,进行了相关试验,去掉了可能影响速度的插件,仍然很慢.以下为对比试验: 1.包含12个自定义字段的项目,更新用时2136ms,记录如下: Sta ...
- kthread_run【转】
转自:http://blog.csdn.net/zhangxuechao_/article/details/50876397 头文件 include/linux/kthread.h 创建并启动 /** ...
- Cortex-M3中C与汇编的交互
以下内容摘自<ARM Cortex-M3权威指南> 概览 在CM3 上编程,既可以使用C 也可以使用汇编.可能还有其它语言的编译器,但是大多数人还是 ...
- [OSG][osgEarth]osgEarth例子程序简介
1.osgearth_graticule:生成经纬线. 2.osgearth_annotation:各类标注(点.线.面.模型.文本等). 3.osgearth_city:加载一个城市三维模型,可以浏 ...
- IOS UIImageView的contentMode属性
红框表示imageView的frame,下面的图片是原图大小UIViewContentModeScaleToFill, 默认,对图片进行拉伸处理(不是按比例),是充满bouns UIVie ...
- SQL Server2014,附加数据库失败,错误为:5120的解决方法
在SQL Server 2014附加数据库的时候,报错为: 无法打开物理文件XXX,操作系统错误5(拒绝访问),SQL Server 错误5120 解决方法: 我的电脑→管理→服务和应用程序→ 服务 ...
- Android混淆打包
一.理论知识 ProGuard是一款免费的Java类文件压缩器.优化器和混淆器.它能发现并删除无用类.字段(field).方法和属性值(attribute).它也能优化字节码并删除无用的指令.最后 ...
- mac os 禁止apache httpd自动启动(转)
mac os 禁止apache httpd自动启动 博客分类: 计算机使用 mac os不像linux有/etc/init.d/rc.local以及service的方式可以设置程序随机启动,而是使 ...
- C#中浮点数依IEEE-754标准转二进制串 (MODBUS 浮点数转换)
因工作需要,把再串口通信中浮点数与字节流的数据转换函数放在这,转发的,谢谢原作者. 今天花了一天的时间搜罗资料,为了解决一个串口编程的进制转化问题.因为串口传送的浮点数据格式与IEEE-754标准(3 ...
- 腾讯QQ你的缓存策略应该改下了
缓存策略基本原则大家都怎么考虑的? 缓存好友数量这个也是醉了,这个数字好像变化频率有点低吧,ok,就算你企鹅用户量大,需要缓存,那肉肉的问一句你这更新策略也不能只管网上涨的,不管往下降的吧?难不成你是 ...