标签:链表
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
vector<int> A;
ListNode *tempL1 = l1;
while (tempL1 != nullptr) {
A.push_back(tempL1->val);
tempL1 = tempL1->next;
}
ListNode *tempL2 = l2;
while (tempL2 != nullptr) {
A.push_back(tempL2->val);
tempL2 = tempL2->next;
}
sort(A.begin(), A.end(), less<int>());
ListNode *l3 = new ListNode(1);
ListNode *ptr = l3;
for (auto iter = A.begin(); iter != A.end(); ++iter)
{
ListNode *temp = new ListNode(*iter);
ptr->next = temp;
ptr = ptr->next;
}
return l3->next;
}
};