LeetCode_590.N叉树的后序遍历

给定一个 N 叉树,返回其节点值的后序遍历

例如,给定一个 3叉树 :

返回其后序遍历: [5,6,3,2,4,1].

说明: 递归法很简单,你可以使用迭代法完成此题吗?

### C#代码
/*
// Definition for a Node.
public class Node {
    public int val;
    public IList<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, IList<Node> _children) {
        val = _val;
        children = _children;
    }
}
*/
public class Solution {
    private IList<int> list = new List<int>();
    public IList<int> Postorder(Node root) {
        if(root != null){
            if(root.children.Any()){
                foreach(var item in root.children){
                    Postorder(item);
                }
            }
            list.Add(root.val);
        }
        return list;
    }
}
原文地址:https://www.cnblogs.com/fuxuyang/p/14244707.html