public:
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
ListNode *result = new ListNode(-1); //哑节点简化代码
ListNode *workNode = result;
while (l1 != nullptr && l2 != nullptr)
{
if (l1->val <= l2->val)
{
workNode->next = l1;
l1 = l1->next;
}
else
{
workNode->next = l2;
l2 = l2->next;
}
workNode = workNode->next;
}
workNode->next = l1 != nullptr ? l1 : l2;
return result->next;
}