当前位置:网站首页>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);
}
}
};
边栏推荐
- 攻防演练中沙盘推演的4个阶段
- Stock account opening is free of charge. Is it safe to open an account on your mobile phone
- 9. Introduction to convolutional neural network
- FOFA-攻防挑战记录
- letcode43:字符串相乘
- 手写一个模拟的ReentrantLock
- ABAP ALV LVC template
- AI zhetianchuan ml novice decision tree
- [Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
- 13. Enregistrement et chargement des modèles
猜你喜欢
跨模态语义关联对齐检索-图像文本匹配(Image-Text Matching)
Invalid V-for traversal element style
Kubernetes static pod (static POD)
1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
Redis, do you understand the list
6.Dropout应用
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
Interface test advanced interface script use - apipost (pre / post execution script)
基于人脸识别实现课堂抬头率检测
8.优化器
随机推荐
网络模型的保存与读取
新库上线 | CnOpenData中华老字号企业名录
50Mhz产生时间
5G NR 系统消息
C#中string用法
NTT template for Tourism
语义分割模型库segmentation_models_pytorch的详细使用介绍
ReentrantLock 公平锁源码 第0篇
跨模态语义关联对齐检索-图像文本匹配(Image-Text Matching)
letcode43:字符串相乘
NVIDIA Jetson test installation yolox process record
接口测试进阶接口脚本使用—apipost(预/后执行脚本)
Cve-2022-28346: Django SQL injection vulnerability
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
韦东山第三期课程内容概要
14.绘制网络模型结构
攻防演练中沙盘推演的4个阶段
Marubeni official website applet configuration tutorial is coming (with detailed steps)
Basic mode of service mesh
Kubernetes static pod (static POD)