-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution559.cs
43 lines (35 loc) · 881 Bytes
/
Solution559.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution559
{
public class Node {
public int val;
public IList<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, IList<Node> _children) {
val = _val;
children = _children;
}
}
/// <summary>
/// 559. Maximum Depth of N-ary Tree - Easy
/// <a href="https://leetcode.com/problems/maximum-depth-of-n-ary-tree">See the problem</a>
/// </summary>
public int MaxDepth(Node root)
{
if (root == null)
{
return 0;
}
int max = 0;
foreach (var child in root.children)
{
max = Math.Max(max, MaxDepth(child));
}
return max + 1;
}
}