90: Binary tree postorder traversal
Given a binary tree, return postorder traversal of the tree
Note: write the
iterativesolution, therecursivesolutionis trivial(see below)
public void PostorderTraversal(TreeNode root)
{
if (root == null)
{
return;
}
PostorderTraversal(root.Left);
PostorderTraversal(root.Right);
Console.WriteLine(root.Value);
}
Example 1
Input: 1
/ \
5 3
Output: [5, 3, 1]
Example 2
Input: 1
\
3
Output: [3, 1]
Helpful article