Easy solution for beginners | DFS
Concept\nIts not a binary tree, so it has no left and right, there could be a number of children so iterate them and add them to result before their parent.\n\n
# Concept\nIts not a binary tree, so it has no left and right, there could be a number of children so iterate them and add them to result before their parent.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\n/*\n// Definition for a Node.\nclass Node {\n    public int val;\n    public List<Node> children;\n\n    public Node() {}\n\n    public Node(int _val) {\n        val = _val;\n    }\n\n    public Node(int _val, List<Node> _children) {\n        val = _val;\n        children = _children;\n    }\n};\n*/\n\nclass Solution {\n    public List<Integer> postorder(Node root) {\n        List<Integer> res = new ArrayList<>();\n\n        if(root==null) return res;\n\n        for(Node child : root.children){\n            res.addAll(postorder(child));\n        }\n        \n        res.add(root.val);\n        return res;\n    }\n}\n```
['Tree', 'Depth-First Search', 'Java']