diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index e20f147f..ff7cbfd1 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -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 { /**