/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* Merge(ListNode* pHead1, ListNode* pHead2) {
ListNode* res = new ListNode(0);
ListNode* p1 = pHead1;
ListNode* p2 = pHead2;
ListNode* cur = res;
while(p1 != nullptr && p2 != nullptr){
if(p1->val <= p2->val){
cur->next = p1;
p1 = p1->next;
cur = cur->next;
}
else{
cur->next = p2;
p2 = p2->next;
cur = cur->next;
}
}
if(p1 != nullptr){
cur->next = p1;
}
else{
cur->next = p2;
}
return res->next;
}
};