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,24 @@
namespace _145._Binary_Tree_Postorder_Traversal;
public class Solution
{
public IList<int> PostorderTraversal(TreeNode root)
{
var result = new List<int>();
if (root == null) return result;
var stack = new Stack<TreeNode>();
stack.Push(root);
while (stack.Any())
{
var cur = stack.Pop();
result.Add(cur.val);
if (cur.left != null)
stack.Push(cur.left);
if (cur.right != null)
stack.Push(cur.right);
}
result.Reverse();
return result;
}
}