Day10
This commit is contained in:
23
94. Binary Tree Inorder Traversal/Solution.cs
Normal file
23
94. Binary Tree Inorder Traversal/Solution.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user