/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
/**
*
* @param pHead1 ListNode类
* @param pHead2 ListNode类
* @return ListNode类
*/
struct ListNode* Merge(struct ListNode* pHead1, struct ListNode* pHead2 ) {
// write code here
if(pHead1==NULL)
return pHead2;
if (pHead2==NULL)
return pHead1;
struct ListNode *temp = malloc(sizeof(struct ListNode));
temp->next=NULL;
if(pHead1->val<=pHead2->val){
temp=pHead1;
temp->next=Merge(pHead1->next,pHead2);
}
else{
temp=pHead2;
temp->next=Merge(pHead1,pHead2->next);
}
return temp;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)