两个升序链表的合并 Merge Two Sorted Lists 【 leetcode】

class Solution {
public:
   ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
   ListNode *p;

  ListNode *p1=p; 
  while(l1!=NULL && l2!=NULL){
      if((l1->val)<(l2->val)){
           p->next=l1;
           p=p->next;
           l1=l1->next;
  }
else{
  p->next=l2;
  p=p->next;
  l2=l2->next;
  }
}

     if(!l1) p->next=l2;
     if(l2==NULL) p->next=l1;
     return p1->next;
}
};

原文地址:https://www.cnblogs.com/julie-yang/p/4644652.html