LeetCode/java/n-ary-tree-postorder-traversal.java
Matej Focko 601c8144e2
java: add «590. N-ary Tree Postorder Traversal»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-08-26 11:31:42 +02:00

21 lines
408 B
Java

import java.util.ArrayList;
import java.util.List;
class Solution {
private ArrayList<Integer> postorder(Node node, ArrayList<Integer> l) {
if (node == null) {
return l;
}
for (var child : node.children) {
postorder(child, l);
}
l.add(node.val);
return l;
}
public List<Integer> postorder(Node root) {
return postorder(root, new ArrayList<Integer>());
}
}