标签:else 有序链表 int link span struct lse tno solution
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode *pHead = new ListNode(-1); ListNode *p = pHead; while (l1 != NULL && l2 != NULL) { if (l1->val <= l2->val) { p->next = l1; p = l1; l1 = l1->next; } else { p->next = l2; p = l2; l2 = l2->next; } } p->next = (l1 == NULL ? l2 : l1); return pHead->next; } };
标签:else 有序链表 int link span struct lse tno solution
原文地址:https://www.cnblogs.com/douzujun/p/12349676.html