-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution559.java
More file actions
48 lines (39 loc) · 1.14 KB
/
Copy pathSolution559.java
File metadata and controls
48 lines (39 loc) · 1.14 KB
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
44
45
46
47
48
package Solutions;
import java.util.ArrayList;
import Execute.Node;
public class Solution559 {
public int maxDepth(Node root) {
if (root == null) return 0;
int res = 1;
for (Node child : root.children) {
res = Math.max(res, maxDepth(child) + 1);
}
return res;
}
public static void main(String[] args){
Node child11 = new Node(11,null);
Node child12 = new Node(12,null);
Node child21 = new Node(21,null);
ArrayList ll =new ArrayList<>();
ll.add(new Node(222,null));
Node child22 = new Node(22,ll);
ll =new ArrayList<>();
ll.add(child11);
ll.add(child12);
Node child1 = new Node(1,ll);
ll =new ArrayList<>();
ll.add(child21);
ll.add(child22);
Node child2 = new Node(2,ll);
ll =new ArrayList<>();
ll.add(child1);
ll.add(child2);
Node root = new Node(10,ll);
// 10
// 1 2
// 11 12 21 22
// 222
Solution559 test = new Solution559();
System.out.println(test.maxDepth(root));
}
}