机械公司网站模板,网站分析表怎么做的,做平台网站要什么条件,wordpress会员中心文章目录 1.解题思路2.代码实现 1.解题思路
在原先链表的每一个元素后面插入一个与前一个相同val的值的结点,然后由于是在原链表进行的操作#xff0c;因此找每个random就变得很方便直接访问即可#xff0c;此题目的精髓是cur1-randomp-random-next,看懂这串代码… 文章目录 1.解题思路2.代码实现 1.解题思路
在原先链表的每一个元素后面插入一个与前一个相同val的值的结点,然后由于是在原链表进行的操作因此找每个random就变得很方便直接访问即可此题目的精髓是cur1-randomp-random-next,看懂这串代码的话这道题也就迎刃而解了.
2.代码实现
struct Node* copyRandomList(struct Node* head){ struct Node* curhead;while(cur){ struct Node* nextcur-next;struct Node*p( struct Node*)malloc(sizeof( struct Node));p-valcur-val;p-nextnext;cur-nextp;curnext;}struct Node* phead;while(p){ struct Node* cur1p-next;if(p-randomNULL){cur1-randomNULL;pcur1-next;}
else
{cur1-randomp-random-next;pcur1-next;
}}struct Node*newnodeNULL;struct Node*tailNULL;while(head){if(tailNULL){tailnewnodehead-next;headhead-next-next;}else{tail-nexthead-next;tailhead-next;headhead-next-next;}}
return newnode;
}结尾今天的分享到此结束喜欢的朋友如果感觉有帮助可以点赞三连支持咱们共同进步!