https://leetcode.com/problems/merge-two-sorted-lists/description/
题目:合并两个排序链表
比较简单,直接附代码:
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
ListNode *p3=new ListNode(0);
ListNode *l3=p3;
while(l1!=NULL&&l2!=NULL){
if(l1->val<l2->val) p3->next=l1,l1=l1->next;
else p3->next=l2,l2=l2->next;
p3=p3->next;
}
p3->next=l1?l1:l2;
return l3->next;
}
};