?LeetCode刷題實戰(zhàn)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?{
????//存放結(jié)果集
????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;
????}
}
評論
圖片
表情
