We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Tree: Preorder Traversal
- Discussions
Tree: Preorder Traversal
Tree: Preorder Traversal
Sort by
recency
|
78 Discussions
|
Please Login in order to post a comment
Python solution:
In C# the input description is horrible. There is no code given, you need to parse input from stdin. First line is number of nodes, second line is list of nodes from which you first need to create the tree, then traverse it. In e.g. Python, the entire tree is already created with appropriate tree structure class. Here is a C# solution:
using System; using System.Collections.Generic; using System.IO; class Solution { public static List res = new List();
}
public class TreeNode(int value, TreeNode? left = null, TreeNode? right = null){ public int Value {get; set;} = value; public TreeNode? Left {get; set;} = left; public TreeNode? Right {get; set;} = right; }
In Go there is no preOrder function.... actually there is no code at all other than an empty main().... happened few times already...
JavaScript Solution:-