当前位置:网站首页>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);
}
}
};边栏推荐
- Qt不同类之间建立信号槽,并传递参数
- Four stages of sand table deduction in attack and defense drill
- fabulous! How does idea open multiple projects in a single window?
- Introduction to paddle - using lenet to realize image classification method I in MNIST
- 手写一个模拟的ReentrantLock
- Deep dive kotlin collaboration (the end of 23): sharedflow and stateflow
- C # generics and performance comparison
- 大二级分类产品页权重低,不收录怎么办?
- 5G NR 系统消息
- C#中string用法
猜你喜欢

8道经典C语言指针笔试题解析

5.过拟合,dropout,正则化

Reptile practice (VIII): reptile expression pack

C # generics and performance comparison

Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch

ReentrantLock 公平锁源码 第0篇

Kubernetes Static Pod (静态Pod)
![Cause analysis and solution of too laggy page of [test interview questions]](/img/8d/3ca92ce5f9cdc85d52dbcd826e477d.jpg)
Cause analysis and solution of too laggy page of [test interview questions]

13. Model saving and loading

赞!idea 如何单窗口打开多个项目?
随机推荐
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Course of causality, taught by Jonas Peters, University of Copenhagen
【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
基于卷积神经网络的恶意软件检测方法
Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
韦东山第三期课程内容概要
[OBS] the official configuration is use_ GPU_ Priority effect is true
SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
3 years of experience, can't you get 20K for the interview and test post? Such a hole?
10.CNN应用于手写数字识别
Reptile practice (VIII): reptile expression pack
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
Basic mode of service mesh
牛客基础语法必刷100题之基本类型
letcode43:字符串相乘
新库上线 | 中国记者信息数据
13.模型的保存和載入
2.非线性回归
1.线性回归