标签:null eth list sorted blog 交通 ade 通过 return
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.
不申请新的节点(把两个链表的节点接起来)
提交通过:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode v(0),*pre = &v,*p = pre; // pre带头结点 while(l1 != NULL && l2 != NULL){ if(l1->val > l2 ->val){ p->next = l2; l2 = l2->next; p = p->next; } else{ p->next = l1; l1 = l1->next; p = p->next; } } if(l1 == NULL ) p->next = l2; else p->next = l1; return pre->next; }
21. Merge Two Sorted Lists合并两个有序链表
标签:null eth list sorted blog 交通 ade 通过 return
原文地址:http://www.cnblogs.com/hozhangel/p/7823326.html