标签:
1 /* 2 struct ListNode { 3 int val; 4 struct ListNode *next; 5 ListNode(int x) : 6 val(x), next(NULL) { 7 } 8 };*/ 9 class Solution { 10 public: 11 ListNode* Merge(ListNode* pHead1, ListNode* pHead2) 12 { 13 if (pHead1 == NULL){ 14 return pHead2; 15 } 16 if (pHead2 == NULL){ 17 return pHead1; 18 } 19 ListNode *p = NULL; 20 if (pHead1->val < pHead2->val){ 21 p = pHead1; 22 p->next = Merge(pHead1->next, pHead2); 23 } 24 else{ 25 p = pHead2; 26 p->next = Merge(pHead1, pHead2->next); 27 } 28 return p; 29 } 30 };
标签:
原文地址:http://www.cnblogs.com/wanderingzj/p/5353050.html