当前位置:网站首页>JZ35 replication of complex linked list
JZ35 replication of complex linked list
2022-04-23 02:41:00 【Rosita.】
Topic link : Replication of complex linked list _ Niuke Tiba _ Cattle from
Be careful :
It mainly considers the corresponding relationship between old and new nodes , as well as random Empty or pointing to your own situation
/*
struct RandomListNode {
int label;
struct RandomListNode *next, *random;
RandomListNode(int x) :
label(x), next(NULL), random(NULL) {
}
};
*/
class Solution {
public:
RandomListNode* Clone(RandomListNode* pHead) {
if(!pHead) return NULL;
// Define the head pointer of the new linked list
RandomListNode* newhead = new RandomListNode(pHead->label);
//po Point to the header of the old linked list ,pn Point to the head of the new list
RandomListNode* po = pHead, *pn = newhead;
// Hash is used to record whether the new node corresponding to the old node has been opened , And store the addresses of the old linked list and the first linked list
unordered_map<RandomListNode*, RandomListNode*> map;
// First traversal . Save the old and new mapping relationship of each node
while(po){
map[po] = new RandomListNode(po->label);
po = po->next;
}
po = pHead;
// The second traversal gives each node random and next Member assignment
while(po){
pn->next = map[po->next];
pn->random = map[po->random];
po = po->next;
pn = pn->next;
}
return newhead;
}
};
版权声明
本文为[Rosita.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230240052786.html
边栏推荐
- [suggestion collection] hematemesis sorting out golang interview dry goods 21 questions - hanging interviewer-1
- Implementation of distributed scenario business operation log (based on redis lightweight)
- php+mysql對下拉框搜索的內容修改
- Day 4 of learning rhcsa
- C # import details
- 1、 Sequence model
- Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
- Deploying sbert model based on torchserve < semantic similarity task >
- Suggestion: block reference sorting is in the order of keywords
- [untitled]
猜你喜欢
[wechat applet] set the bottom menu (tabbar) for the applet
Implementation of distributed scenario business operation log (based on redis lightweight)
Parental delegation model [understanding]
JVM类加载器
每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
高效音乐格式转换工具Music Converter Pro
Global, exclusive and local routing guard
day18--栈队列
Target narak
手写内存池以及原理代码分析【C语言】
随机推荐
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
Fashion MNIST dataset classification training
Flink stream processing engine system learning (II)
认识进程(多线程_初阶)
So library dependency
Hack the box optimum
grain rain
C语言 171. 最近回文数
006_ redis_ Jedis quick start
下载正版Origin Pro 2022 教程 及 如何 激 活
013_ Analysis of SMS verification code login process based on session
Use of go language web Middleware
Servlet template engine usage example
手写内存池以及原理代码分析【C语言】
想用Mac学习sql,主要给自己个充足理由买Mac听听意见
Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
This is how the power circuit is designed
【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
Cuisine leetcode
Execute external SQL script in MySQL workbench and report error