Day i do not know
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_104._Maximum_Depth_of_Binary_Tree</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
104. Maximum Depth of Binary Tree/Program.cs
Normal file
9
104. Maximum Depth of Binary Tree/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _104._Maximum_Depth_of_Binary_Tree;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
26
104. Maximum Depth of Binary Tree/Solution.cs
Normal file
26
104. Maximum Depth of Binary Tree/Solution.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace _104._Maximum_Depth_of_Binary_Tree;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public int MaxDepth(TreeNode root)
|
||||
{
|
||||
var res = Recursion(0, root);
|
||||
if (root != null)
|
||||
res++;
|
||||
return res;
|
||||
}
|
||||
|
||||
private int Recursion(int count, TreeNode node)
|
||||
{
|
||||
if(node == null)
|
||||
return 0;
|
||||
var list = new List<int>();
|
||||
if (node.left != null)
|
||||
list.Add(Recursion(count + 1, node.left));
|
||||
if (node.right != null)
|
||||
list.Add(Recursion(count + 1, node.right));
|
||||
if (list.Count > 0)
|
||||
return list.Max();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
15
104. Maximum Depth of Binary Tree/TreeNode.cs
Normal file
15
104. Maximum Depth of Binary Tree/TreeNode.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace _104._Maximum_Depth_of_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