mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0104.二叉树的最大深度.md
增加559N Java 递归方法
This commit is contained in:
@ -312,6 +312,24 @@ class solution {
|
||||
```
|
||||
|
||||
### 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
|
||||
class solution {
|
||||
/**
|
||||
|
Reference in New Issue
Block a user