当前位置:网站首页>133. Clone map
133. Clone map
2022-07-08 00:59:00 【anieoo】
Original link :133. Clone map
solution:
dfs Establish the mapping from the origin to the clone point , You can traverse it once
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> neighbors;
Node() {
val = 0;
neighbors = vector<Node*>();
}
Node(int _val) {
val = _val;
neighbors = vector<Node*>();
}
Node(int _val, vector<Node*> _neighbors) {
val = _val;
neighbors = _neighbors;
}
};
*/
class Solution {
public:
unordered_map<Node *, Node *> hash;
Node* cloneGraph(Node* node) {
if(node == NULL) return node;
dfs(node); // Building mapping
for(auto [s, d] : hash) {
for(auto ver : s->neighbors) {
d->neighbors.push_back(hash[ver]);
}
}
return hash[node];
}
//dfs Used to realize the mapping from the original point to the clone point
void dfs(Node *root) {
hash[root] = new Node(root->val);
for(auto ver : root->neighbors) {
if(hash[ver] == 0)
dfs(ver);
}
}
};
边栏推荐
- Four stages of sand table deduction in attack and defense drill
- STL--String类的常用功能复写
- Introduction to paddle - using lenet to realize image classification method I in MNIST
- Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
- My best game based on wechat applet development
- 4.交叉熵
- Codeforces Round #804 (Div. 2)
- 完整的模型验证(测试,demo)套路
- Hotel
- 串口接收一包数据
猜你喜欢
A network composed of three convolution layers completes the image classification task of cifar10 data set
国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
13.模型的保存和载入
jemter分布式
图像数据预处理
SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
Deep dive kotlin synergy (XXII): flow treatment
13.模型的保存和載入
Interface test advanced interface script use - apipost (pre / post execution script)
Codeforces Round #804 (Div. 2)(A~D)
随机推荐
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
AI zhetianchuan ml novice decision tree
New library online | cnopendata China Star Hotel data
3.MNIST数据集分类
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
Introduction to paddle - using lenet to realize image classification method I in MNIST
DNS series (I): why does the updated DNS record not take effect?
Qt不同类之间建立信号槽,并传递参数
图像数据预处理
ReentrantLock 公平锁源码 第0篇
Service Mesh介绍,Istio概述
网络模型的保存与读取
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
Jemter distributed
Interface test advanced interface script use - apipost (pre / post execution script)
QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
Reentrantlock fair lock source code Chapter 0
【深度学习】AI一键换天
133. 克隆图
Lecture 1: the entry node of the link in the linked list