image_2022-04-01_16-16-16.png
33.5 KB
#N589. N-ary Tree Preorder Traversal
problem link
#solution
problem link
#solution
class Solution {
List<Integer> list = new ArrayList<>();
public List<Integer> preorder(Node root) {
if(root==null) return list;
list.add(root.val);
for(int i=0; i<root.children.size(); i++){
preorder(root.children.get(i));
}
return list;
}
}