题目
#include<iostream>
#include<vector>
using namespace std;
struct Listnode {
int val;
Listnode* next;
Listnode(int x) :val(x), next(NULL) {}
};
Listnode* createList(vector<int>& nums) {
if (nums.size() == 0) {
return NULL;
}
Listnode* head = new Listnode(nums[0]);
Listnode* curnode = head;
for (int i = 1; i < nums.size(); i++) {
curnode->next = new Listnode(nums[i]);
curnode = curnode->next;
}
return head;
}
Listnode* merge(Listnode* l1, Listnode* l2) {
Listnode* dummy = new Listnode(0);
Listnode* cur = dummy;
while (l1 != NULL && l2 != NULL) {
if (l1->val < l2->val)
{
cur->next = l1;
l1 = l1->next;
}
else {
cur->next = l2;
l2 = l2->next;
}
cur