Problem
Given an n-ary tree, return the postorder traversal of its nodes’ values.
Example
given a 3-ary
tree:
Return its postorder traversal as: [5,6,3,2,4,1]
.
Solution1
Method: Recursive
Time Complexity:
Space Complexity:
1 | """ |
Solution2
Method: Iterative
Time Complexity:
Space Complexity:
1 | """ |
or
1 | """ |