Day i do not know
This commit is contained in:
11
226. Invert Binary Tree/226. Invert Binary Tree.csproj
Normal file
11
226. Invert Binary Tree/226. Invert Binary Tree.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_226._Invert_Binary_Tree</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
226. Invert Binary Tree/Program.cs
Normal file
9
226. Invert Binary Tree/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _226._Invert_Binary_Tree;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
23
226. Invert Binary Tree/Solution.cs
Normal file
23
226. Invert Binary Tree/Solution.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
16
226. Invert Binary Tree/TreeNode.cs
Normal file
16
226. Invert Binary Tree/TreeNode.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace _226._Invert_Binary_Tree;
|
||||
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user