138. N-ary Tree Preorder Traversal

Given the root of an n-ary tree root, return the node values in preorder: root, then children from left to right. The tree is given in the format: [root, null, root_children, null, next_node_children, ...].
Example 1
Input: root = [1]
Output: [1]
Explanation: Tree with a single node.
Example 2
Input: root = [1,null,3,2,4,null,5,6]
Output: [1,3,5,6,2,4]
Explanation: Preorder: root, then children's subtrees left to right.
easyn-ary treerecursionstacktree
JavaScript
Loading...
Line 1, Char 1