lc590.java 644 字节
Newer Older
L
liu13 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package code;

import java.util.ArrayList;
import java.util.List;

public class lc590 {
    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val,List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    List<Integer> res;
    public List<Integer> postorder(Node root) {
        res = new ArrayList<>();
        helper(root);
        return res;
    }

    public void helper(Node root){
        if(root==null) return;
        for(Node nd:root.children){
            helper(nd);
        }
        res.add(root.val);
    }
}