Problem List

N-ary Tree Postorder Traversal

May 30, 2025Go stack, tree, depth first searcheasy

Problem

Reflections

Memorized at this point. For the record I am not merely copying the dfs func from previous challenges. I am rewriting it each time.

Performance

Complexity

Go Solution
func postorder(root *Node) []int {
    var res []int
    var dfs func(node *Node)
    dfs = func(node *Node) {
        if node == nil {
            return
        }

        for _,child := range(node.Children) {
            dfs(child)
        }
        res = append(res, node.Val)
    }
    dfs(root)
    return res
}
LeetCode Problem Link