Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-04-01_16-16-16.png
33.5 KB
#N589. N-ary Tree Preorder Traversal
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;
}
}