[LeetCode] 133. Clone Graph
来源:互联网 发布:阿里云 短信 编辑:程序博客网 时间:2024/06/07 00:35
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node) { return node == nullptr ? nullptr : DFS(node); }private: unordered_map<int, UndirectedGraphNode *> ToCopied; UndirectedGraphNode *DFS(UndirectedGraphNode *node) { UndirectedGraphNode *copiednode = new UndirectedGraphNode(node->label); ToCopied[node->label] = copiednode; for (auto neighbor : node->neighbors) { if (ToCopied.find(neighbor->label) == ToCopied.end()) { copiednode->neighbors.push_back(DFS(neighbor)); } else { copiednode->neighbors.push_back(ToCopied[neighbor->label]); } } return copiednode; }};
阅读全文
0 0
- LeetCode 133. Clone Graph
- [Leetcode] 133. Clone Graph
- [leetcode] 133.Clone Graph
- Leetcode 133. Clone Graph
- 133. Clone Graph LeetCode
- LeetCode 133. Clone Graph
- leetcode 133. Clone Graph
- LeetCode *** 133. Clone Graph
- leetcode-133. Clone Graph
- LeetCode 133. Clone Graph
- [LeetCode] 133. Clone Graph
- LeetCode: 133. Clone Graph
- Leetcode-133. Clone Graph
- Leetcode 133. Clone Graph
- LeetCode 133. Clone Graph
- leetcode 133. Clone Graph
- [LeetCode]133. Clone Graph
- 【leetcode】133. Clone Graph
- 微习惯--简单到四个
- WOJ1036-Cards
- centos 7 安装nodejs
- springMVC处理表单重复提交,包含页面多个嵌套提交的情况,自定义token处理
- 基础概念:Oracle数据库、实例、用户、表空间、表之间的关系
- [LeetCode] 133. Clone Graph
- Scala入门笔记
- NC开发笔记——单据模板编辑显示公式使用
- C#中Socket通信编程的异步实现
- iOS 判断网络连接状态的几种方法
- Foursquare数据集处理之利用defaultdict进行主次关键字排序
- leetcode- Beautiful Arrangement II
- RecyclerView 多布局使用
- httpURLConnection