题目描述:
很简单,进行后续遍历
代码:
/*
// 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> postorder(Node root) {
List<Integer> result = new ArrayList<>();
gets(root, result);
return result;
}
public void gets(Node root,List<Integer> result){
if(root == null){
return ;
}
List<Node> get = root.children;
for (Node node : get) {
gets(node, result);
}
result.add(root.val);
}
}