0590. Postorder Traversal
Easy | Tree + Recursion / Stack | 32 ms (98.77%), 16.3 MB (94.57%)
Source: LeetCode - N-ary Tree Postorder Traversal GitHub: Solution / Performance
Given the root
of 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?
For recursive solution, visiting the children (list of nodes) in the right order.
For iterative solution, visiting the children (list of nodes) reversely.
Excepting the above hints, we visit the child nodes first before appending each node's value.
Last updated