590. N-ary Tree Postorder Traversal*
https://leetcode.com/problems/n-ary-tree-postorder-traversal/
题目描述
Given an n-ary tree, return the postorder traversal of its nodes’ values.
Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).
Follow up:
Recursive solution is trivial, could you do it iteratively?
Example 1:
Example 2:
Constraints:
- The height of the
n-ary
tree is less than or equal to 1000 - The total number of nodes is between
[0, 10^4]
C++ 实现 1
递归的方式.
C++ 实现 2
迭代的方式. 迭代的方式可以仔细研究一下, children 按顺序入栈, 最后 reverse res
.