https://leetcode.com/problems/n-ary-tree-preorder-traversal/ Easy

Решение

class Solution {
    fun preorder(root: Node?): List<Int> {
        val res = ArrayList<Int>()
        fun dfs(n: Node?) {
            if (n == null) return
            res.add(n.`val`)
            for (c in n.children) dfs(c)
        }
        dfs(root)
        return res
    }
}