21 Merge Two Sorted Lists
2015-11-14 20:31
337 查看
/** * 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* head = new ListNode(0); ListNode* now = head; while(l1&&l2) { if(l1->val<l2->val) { now->next = l1; l1 = l1->next; } else { now->next = l2; l2 = l2->next; } now = now->next; } if(l1==NULL) now->next = l2; else now->next = l1; return head->next; } };
相关文章推荐
- 232 Implement Queue using Stacks
- QNX os supported board(ARM+MIPS+POWERPC+X86)
- Java继承 学习 && 类初始化顺序
- 记录下,系统下命令都不能用
- 202 Happy Number
- 在matlab环境下LIBSVM的demo
- 263 Ugly Number
- Ugly Number II
- iar for 8051 v8.30破解文件的使用
- 70 Climbing Stairs
- Codeforces Round #328 (Div. 2) D. Super M
- OC协议的应用-代理
- 伪目标
- JavaScript之再谈回调与闭包
- iOS性能优化:Instruments使用实战
- 83 Remove Duplicates from Sorted List
- 时序图学习笔记
- 《大道至简》软件工程
- iOS9的新特性以及适配方案
- 论PHP常见的漏洞