ListNode* Merge(ListNode* pHead1, ListNode* pHead2) { ListNode *res = new ListNode(0); ListNode*current = res; if (pHead1 == NULL&&pHead2!=NULL){ return pHead2; }else if (pHead1 != NULL&&pHead2==NULL){ return pHead1; }else if (pHead1 == NULL &&pHead2 == NULL){ return NULL; } else{ while (pHead1!=NULL && pHead2!=NULL) { if (pHead1->val < pHead2->val){ current->next = pHead1; current = current->next; pHead1 = pHead1->next; } else{ current->next = pHead2; current = current->next; pHead2 = pHead2->next; } } if (pHead1 == NULL){ while (pHead2) { current->next = pHead2; current = current->next; pHead2 = pHead2->next; } } if (pHead2 == NULL){ while (pHead1) { current->next = pHead1; current = current->next; pHead1 = pHead1->next; } } } res = res->next; return res; } 和你的代码很像...可惜我写了一坨屎..
点赞

相关推荐

饿魔:看到在线简历了吧
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务