Day i do not know
This commit is contained in:
11
101. Symmetric Tree/101. Symmetric Tree.csproj
Normal file
11
101. Symmetric Tree/101. Symmetric Tree.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_101._Symmetric_Tree</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
13
101. Symmetric Tree/Program.cs
Normal file
13
101. Symmetric Tree/Program.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace _101._Symmetric_Tree;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var t = new TreeNode(3,
|
||||
new TreeNode(4, new TreeNode(5, new TreeNode(6), null), null),
|
||||
new TreeNode(4, null, new TreeNode(5, null, new TreeNode(6)))
|
||||
);
|
||||
Console.WriteLine(new Solution().IsSymmetric(t));
|
||||
}
|
||||
}
|
||||
20
101. Symmetric Tree/Solution.cs
Normal file
20
101. Symmetric Tree/Solution.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace _101._Symmetric_Tree;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public bool IsSymmetric(TreeNode root)
|
||||
{
|
||||
return Recursion(root.left, root.right);
|
||||
}
|
||||
|
||||
private bool Recursion(TreeNode? left, TreeNode? right)
|
||||
{
|
||||
if ((left == null) != (right == null))
|
||||
return false;
|
||||
if (left == null || right == null)
|
||||
return true;
|
||||
if (left.val != right.val)
|
||||
return false;
|
||||
return Recursion(left.left, right.right) && Recursion(left.right, right.left);
|
||||
}
|
||||
}
|
||||
17
101. Symmetric Tree/TreeNode.cs
Normal file
17
101. Symmetric Tree/TreeNode.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace _101._Symmetric_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