首页 > 其他 > 详细

LeetCode 21. Merge Two Sorted Lists

时间:2016-03-10 21:58:57      阅读:224      评论:0      收藏:0      [点我收藏+]
 1 class Solution {
 2 public:
 3     ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
 4         ListNode* head = new ListNode(0);
 5         ListNode* res = head;
 6         while(l1 != NULL && l2 != NULL){
 7             if(l1->val < l2->val){
 8                 head->next = l1;
 9                 head = head->next;
10                 l1 = l1->next;
11             }
12             else{
13                 head->next = l2;
14                 head = head->next;
15                 l2 = l2->next;
16             }
17         }
18         if(l1 != NULL) head->next = l1;
19         else if(l2 != NULL) head->next = l2;
20         return res->next;
21     }
22 };

 

LeetCode 21. Merge Two Sorted Lists

原文:http://www.cnblogs.com/co0oder/p/5263479.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!