21. Merge Two Sorted Lists
来源:互联网 发布:英文翻译什么软件好 编辑:程序博客网 时间:2024/06/07 19:28
题目原文
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.
代码
class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if(!l1&&!l2) return NULL; if(!l1&&l2) return l2; if(l1&&!l2) return l1; ListNode* start,*cur; if(l1->val<l2->val){ start=l1; cur=start; l1=l1->next; } else{ start=l2; cur=start; l2=l2->next; } for(;l1&&l2;){ if(l1->val<l2->val){ cur->next=l1; l1=l1->next; cur=cur->next; } else{ cur->next=l2; l2=l2->next; cur=cur->next; } } if(l1) cur->next=l1; if(l2) cur->next=l2; return start; }};
0 0
- 21.Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21.Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- 21. Merge Two Sorted Lists
- iOS - Swift 关于颜色的一些方法
- 20. Valid Parentheses
- Android之RatingBar实现评论星级效果
- Android性能优化第(十)篇---布局优化
- 代数笔记-第二章-群
- 21. Merge Two Sorted Lists
- ZJOI 2008 瞭望塔 半平面交
- Android API Guide for Media and Camera(一)—— 媒体与相机(媒体播放器)
- Ubuntu下mysql常用操作
- atom添加背景颜色
- 100. Same Tree
- 指针和数组
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- AWS坑