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,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;
}
}