class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { ListNode *dummy = new ListNode(-1); ListNode *p = dummy, *p1 = list1, *p2 = list2; while (p1 != NULL && p2 != NULL) { if (p1->val > p2->val) { p->next = p2; p2 = p2->next; } else { p->next = p1; p1 = p1->next; } p = p->next; } if (p1 != NULL) p->next = p1; if (p2 != NULL) p->next = p2; return dummy->next; } };
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)