当前位置:网站首页>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);
}
}
};
边栏推荐
- 6.Dropout应用
- jemter分布式
- 3.MNIST数据集分类
- QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
- Invalid V-for traversal element style
- 130. 被围绕的区域
- How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
- Service mesh introduction, istio overview
- 【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
- 炒股开户怎么最方便,手机上开户安全吗
猜你喜欢
Cve-2022-28346: Django SQL injection vulnerability
利用GPU训练网络模型
Cancel the down arrow of the default style of select and set the default word of select
Redis, do you understand the list
What does interface testing test?
DNS series (I): why does the updated DNS record not take effect?
My best game based on wechat applet development
9. Introduction to convolutional neural network
国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
13.模型的保存和载入
随机推荐
韦东山第二期课程内容概要
Jemter distributed
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
Handwriting a simulated reentrantlock
The weight of the product page of the second level classification is low. What if it is not included?
网络模型的保存与读取
Stock account opening is free of charge. Is it safe to open an account on your mobile phone
【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
The whole life cycle of commodity design can be included in the scope of industrial Internet
Service mesh introduction, istio overview
基础篇——整合第三方技术
Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
4.交叉熵
Codeforces Round #804 (Div. 2)(A~D)
STL--String类的常用功能复写
AI zhetianchuan ml novice decision tree
图像数据预处理
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现