590. N 叉树的后序遍历
今天的简单题,基础的后序遍历递归写法,就不多做描述了
class Solution {
List<Integer> list = new ArrayList<>();
public List<Integer> postorder(Node root) {
dfs(root);
return list;
}
void dfs (Node root) {
if (root == null) return;
for (Node node : root.children) dfs(node);
list.add(root.val);
}
}