1 Star 1 Fork 0

laodasbch/Leetcode-Complete-Guide

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1490.txt 902 Bytes
一键复制 编辑 原始数据 按行查看 历史
junbinLiang 提交于 2020-08-27 12:58 +08:00 . move
思路:简单的n-tree 遍历
代码:
/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {
children = new ArrayList<Node>();
}
public Node(int _val) {
val = _val;
children = new ArrayList<Node>();
}
public Node(int _val,ArrayList<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
Map<Node,Node>map=new HashMap<>();
public Node cloneTree(Node root) {
if(root==null)return null;
Node R=new Node(root.val);
dfs(root,R);
return R;
}
public void dfs(Node root,Node R){
if(root==null)return;
List<Node>childs=root.children;
for(Node c:childs){
Node node=new Node(c.val);
R.children.add(node);
dfs(c,node);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/laodasbch/Leetcode-Complete-Guide.git
git@gitee.com:laodasbch/Leetcode-Complete-Guide.git
laodasbch
Leetcode-Complete-Guide
Leetcode-Complete-Guide
master

搜索帮助