输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然是按照递增排序的。
class Solution { public: ListNode* merge(ListNode* l1, ListNode* l2) { auto dummy = new ListNode(-1); auto cur = dummy; while (l1 && l2) { if (l1->val <= l2->val) { cur->next = l1; l1 = l1->next; } else { cur->next = l2; l2 = l2->next; } cur = cur->next; } if (l2) cur->next = l2; if (l1) cur->next = l1; return dummy->next; } };
标签:ListNode,cur,合并,next,链表,l2,l1,排序 From: https://www.cnblogs.com/leetothemoon/p/16983901.html