Press "Enter" to skip to content

Posts tagged as “traversla”

花花酱 LeetCode 589. N-ary Tree Preorder Traversal

Problem

Given an n-ary tree, return the preorder traversal of its nodes’ values.

 

For example, given a 3-ary tree:

 

Return its preorder traversal as: [1,3,5,6,2,4].

 

Note: Recursive solution is trivial, could you do it iteratively?

Solution1: Recursive

Solution2: Iterative

Related Problems