This commit is contained in:
Electrominch
2022-10-12 02:30:23 +03:00
parent 02afed9c4c
commit 01c5720116
39 changed files with 517 additions and 30 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_94._Binary_Tree_Inorder_Traversal</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
namespace _94._Binary_Tree_Inorder_Traversal;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}

View File

@@ -0,0 +1,23 @@
namespace _94._Binary_Tree_Inorder_Traversal;
public class Solution
{
public List<int> inorderTraversal(TreeNode root)
{
List<int> res = new List<int>();
Stack<TreeNode> stack = new Stack<TreeNode>();
TreeNode? curr = root;
while (curr != null || stack.Count > 0)
{
while (curr != null)
{
stack.Push(curr);
curr = curr.left;
}
curr = stack.Pop();
res.Add(curr.val);
curr = curr.right!;
}
return res;
}
}

View File

@@ -0,0 +1,15 @@
namespace _94._Binary_Tree_Inorder_Traversal;
//Definition for a binary tree node.
public class TreeNode
{
public int val;
public TreeNode? left;
public TreeNode? right;
public TreeNode(int val = 0, TreeNode? left = null, TreeNode? right = null)
{
this.val = val;
this.left = left;
this.right = right;
}
}