LeetCode刷题实战590:N 叉树的后序遍历
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 {
//存放结果集
Listres = new ArrayList<>();
public Listpostorder(Node root) {
if (root == null) return res;
for (Node child : root.children) {
postorder(child);
}
//后序遍历
res.add(root.val);
return res;
}
}
评论
