Merge Two Sorted Lists
来源:互联网 发布:php伪造来路ip 编辑:程序博客网 时间:2024/06/05 20:51
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.
solution: use recursive method.
#include <algorithm>/** * 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) { if(!l1 || l2 && l1->val > l2->val) swap(l1, l2);//l1 point to the small pointer. if(l1) l1->next = mergeTwoLists(l1->next, l2);//if l1 is NULL, end. return l1; }};
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
- tesseract使用的一些方法-ocr
- 右键菜单功能动态生成子项
- Invalid project description
- 内网编译thrift 0.8
- phpQuery—基于jQuery的PHP实现
- Merge Two Sorted Lists
- Java MVC与封装示例
- 简单Socket通信
- Android输入法框架分析
- 信号
- C# 使chart控件X轴坐标从0开始,而不是从-1开始的一种解决办法
- Quartz使用
- 高通平台android开发总结
- Linux tcpdump命令详解