解决了!原因是破坏了原来的链表结构。 class Solution { public:     RandomListNode* Clone(RandomListNode* pHead)     {         if(pHead==nullptr)             return pHead;        RandomListNode* head=new RandomListNode(0);         RandomListNode* p=head;         RandomListNode* cur=pHead;         //复制        while(cur)        {            p->next=cur;            p=p->next;            cur=cur->next;            RandomListNode* newhead=new RandomListNode(p->label);            p->next=newhead;            p=p->next;        }         cur=head->next;         p=cur->next;         //链接指针        while(cur)        {            if(cur->random)                p->random=cur->random->next;            else                 p->random=cur->random;            cur=p->next;            if(cur)                p=cur->next;        }         cur=head;         p=cur->next;         //拆分         RandomListNode* keep=new RandomListNode(0);         RandomListNode* tail=keep;        while(p)        {            cur->next=p->next;            cur=cur->next;            tail->next=p;            tail=p;            p=cur->next;        }         tail->next=nullptr;         pHead=keep->next;         return head->next;     } };
点赞 评论

相关推荐

小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
让资本家给我当牛做马:26的秋招还没开始啊?你找的是实习?实习的话你马上就研三了为什么还要实习?
点赞 评论 收藏
分享
投递长鑫存储等公司7个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务