> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/04-05-2022-590.-n-ary-tree-postorder-traversal.md).

# 04/05/2022 590. N-ary Tree Postorder Traversal

```
// Some code
class Solution {
    public List<Integer> postorder(Node root) {
        List<Integer> result = new LinkedList<>();
        if (root == null) return result;
        dfs(root, result);
        result.add(root.val);
        return result;       
    }
    
    private void dfs(Node root, List<Integer> result){
        if (root == null) return;
        for (Node child: root.children){
            dfs(child, result);
            result.add(child.val);
        }
    }
}
```

```
// Some code
class Solution {
    public List<Integer> postorder(Node root) {
        LinkedList<Integer> result = new LinkedList<>();
        if (root == null) return result;
        Deque<Node> stack = new LinkedList<>();
        stack.push(root);
        while (!stack.isEmpty()){
            Node curr = stack.pop();
            result.addFirst(curr.val);
            for (Node child: curr.children){
                stack.push(child);
            }
        }
        return result;
    }
}
```
