【Merge two sorted】 --MyLeetCode(七)
来源:互联网 发布:linux配置自动获取ip 编辑:程序博客网 时间:2024/06/05 01:58
Description:
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 tmpL(0); ListNode* tail = &tmpL; while(l1 && l2){ if(l1->val < l2->val){ tail->next = l1; l1 = l1->next; } else{ tail->next = l2; l2 = l2->next; } tail = tail->next; } tail->next = l1 ? l1 : l2; return tmpL.next; }};
阅读全文
0 0
- 【Merge two sorted】 --MyLeetCode(七)
- 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
- reactivecocoa框架 、MVC 和 MVVM 的理解
- SDK窗口编程 输出一个在窗口永远居中的字符串
- 在ubuntu上搭建django生产环境
- CTF 中 Bash中的小技巧
- Swift 字符(Character)
- 【Merge two sorted】 --MyLeetCode(七)
- [Oracle Support]PeopleSoft Support中Fixes,Patches,Bundles,Packs?
- MongoDB存储结构
- vim编辑器的一些其他用法
- (牧飞)搭建自己的pip源
- 使用TabLayout和ViewPager实现顶部标签页
- 想学H5的用哪些软件好
- 【DL--22】实现神经网络算法NeuralNetwork以及手写数字识别
- Android福利来了,很快Android手机能吃上「奥利奥」了