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