代码拉取完成,页面将自动刷新
package code;
import java.util.ArrayList;
import java.util.List;
/*
* 589. N-ary Tree Preorder Traversal
* 题意:多叉树先序遍历
* 难度:Easy
* 分类:Tree
* 思路:
* Tips:
*/
public class lc589 {
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val,List<Node> _children) {
val = _val;
children = _children;
}
}
List<Integer> res;
public List<Integer> preorder(Node root) {
res = new ArrayList<>();
helper(root);
return res;
}
public void helper(Node root){
if(root==null) return;
res.add(root.val);
for(Node nd:root.children){
helper(nd);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。