Merge pull request #881 from hailincai/patch1029

Update 0104.二叉树的最大深度.md
This commit is contained in:
程序员Carl
2021-11-05 22:44:13 +08:00
committed by GitHub

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 {
/** /**