Merge Two Sorted Lists
来源:互联网 发布:南京大学软件学院硕士 编辑:程序博客网 时间:2024/05/17 02:36
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
题目要求:要求合并两个有序链表
代码如下:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode*p=l1,*q=l2; if(!l1) return l2; if(!l2) return l1; ListNode*res=new ListNode(0),*slo=res; while(p&&q) { if(p->val<=q->val) { slo->next=p; p=p->next; } else { slo->next=q; q=q->next; } slo=slo->next; } if(p) slo->next=p; else if(q) slo->next=q; return res->next; }};
0 0
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- Merge Two Sorted Lists
- openURL
- android JSON数据解析分析
- 架构设计:系统间通信(13)——RPC实例Apache Thrift 下篇(1)
- 中文路径, 文件转换
- Redis集群架构部署(Version 3.0.7)
- Merge Two Sorted Lists
- ASP.NET 的服务器控件,GridView传多个参数
- iOS9如何调用系统通讯录
- java学习资源
- Android字符串映射找resource下资源
- Android studio把model打成aar包,还有so文件和aar文件的使用
- C 语言字符数组的定义与初始化
- ecshop数据库操作函数
- Cloudera Manager(CDH5)内部结构、功能包括配置文件、目录位置等