Update 0104.二叉树的最大深度.md

增加559N Java 递归方法
This commit is contained in:
hailincai
2021-10-29 08:16:18 -04:00
committed by GitHub
parent ff2fcaeff2
commit a8ef4fe6ee

View File

@ -312,6 +312,24 @@ class solution {
``` ```
### 559.n叉树的最大深度 ### 559.n叉树的最大深度
```java
class Solution {
/*递归法后序遍历求root节点的高度*/
public int maxDepth(Node root) {
if (root == null) return 0;
int depth = 0;
if (root.children != null){
for (Node child : root.children){
depth = Math.max(depth, maxDepth(child));
}
}
return depth + 1; //中节点
}
}
```
```java ```java
class solution { class solution {
/** /**