当前位置:网站首页>133. 克隆图
133. 克隆图
2022-07-07 23:18:00 【anieoo】
原题链接:133. 克隆图
solution:
dfs建立原点到克隆点的映射,在遍历一遍即可
/*
// 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); //建立映射
for(auto [s, d] : hash) {
for(auto ver : s->neighbors) {
d->neighbors.push_back(hash[ver]);
}
}
return hash[node];
}
//dfs用来实现原来的点到克隆点的映射
void dfs(Node *root) {
hash[root] = new Node(root->val);
for(auto ver : root->neighbors) {
if(hash[ver] == 0)
dfs(ver);
}
}
};边栏推荐
- Class head up rate detection based on face recognition
- Cancel the down arrow of the default style of select and set the default word of select
- Service mesh introduction, istio overview
- 德总理称乌不会获得“北约式”安全保障
- 丸子官网小程序配置教程来了(附详细步骤)
- NVIDIA Jetson test installation yolox process record
- 2.非线性回归
- [go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation
- AI zhetianchuan ml novice decision tree
- 股票开户免费办理佣金最低的券商,手机上开户安全吗
猜你喜欢

ReentrantLock 公平锁源码 第0篇

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

基于人脸识别实现课堂抬头率检测

The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log

What if the testing process is not perfect and the development is not active?

13. Model saving and loading

接口测试进阶接口脚本使用—apipost(预/后执行脚本)

13. Enregistrement et chargement des modèles

C # generics and performance comparison

Kubernetes static pod (static POD)
随机推荐
新库上线 | CnOpenData中国星级酒店数据
【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Cancel the down arrow of the default style of select and set the default word of select
LeetCode刷题
fabulous! How does idea open multiple projects in a single window?
语义分割模型库segmentation_models_pytorch的详细使用介绍
tourist的NTT模板
丸子官网小程序配置教程来了(附详细步骤)
NVIDIA Jetson测试安装yolox过程记录
取消select的默认样式的向下箭头和设置select默认字样
3.MNIST数据集分类
ReentrantLock 公平锁源码 第0篇
Basic mode of service mesh
ABAP ALV LVC模板
股票开户免费办理佣金最低的券商,手机上开户安全吗
【笔记】常见组合滤波电路
13. Enregistrement et chargement des modèles
FOFA-攻防挑战记录