65: Binary tree inorder traversal
Given a binary tree
, return inorder traversal
of the tree
Note: write the
iterative
solution, therecursive
solutionis trivial
(see below)
public void InorderTraversal(TreeNode root)
{
if (root == null)
{
return;
}
InorderTraversal(root.Left);
Console.WriteLine(root.Value);
InorderTraversal(root.Right);
}
Example 1
Input: 1
/ \
5 3
Output: [5, 1, 3]
Example 2
Input: 1
\
3
Output: [1, 3]