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; } 和你的代码很像...可惜我写了一坨屎..
点赞

相关推荐

05-19 19:54
已编辑
杭州电子科技大学 Java
程序员小白条:《备考软考软件设计师》中级很简单的,不需要花很多时间,除非考软高,这简历找找杭州本地中小厂吧,也很难,项目这块还是最好有自己开发的思考,不要网上的亮点搬过来就行,看运气,本地有优势
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务