/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val,List<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public List<Integer> preorder(Node root) {
List<Integer> ans=new ArrayList<>();
if(root==null){
return ans;
}
ans.add(root.val);
if(root.children!=null){
int len=root.children.size();
for(int i=0;i<len;++i){
List<Integer> temp=preorder(root.children.get(i));
ans.addAll(temp);
}
}
else{
return ans;
}
return ans;
}
}