Given the root of an n-ary tree, return the postorder traversal of its nodes’ values.
Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)
示例

解题
class Solution {
//存放结果集
List<Integer> res = new ArrayList<>();
public List<Integer> postorder(Node root) {
if (root == null) return res;
for (Node child : root.children) {
postorder(child);
}
//后序遍历
res.add(root.val);
return res;
}
}
本篇文章来源于微信公众号:程序IT圈
原创文章,作者:栈长,如若转载,请注明出处:https://www.cxyquan.com/22431.html