Day i do not know

This commit is contained in:
Electrominch
2022-10-18 00:45:31 +03:00
parent 01c5720116
commit 284b6ff10c
72 changed files with 1256 additions and 12 deletions

View File

@@ -0,0 +1,23 @@
namespace _226._Invert_Binary_Tree;
public class Solution
{
public TreeNode? InvertTree(TreeNode root)
{
Stack<TreeNode> stack = new Stack<TreeNode>();
if (root != null)
stack.Push(root);
while (stack.Count > 0)
{
TreeNode cur = stack.Pop();
TreeNode? buf = cur.left;
cur.left = cur.right;
cur.right = buf;
if (cur.right != null)
stack.Push(cur.right);
if (cur.left != null)
stack.Push(cur.left);
}
return root;
}
}