diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index b74529d6..a7c206af 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -313,6 +313,31 @@ class solution { } ``` +```java +class Solution { + /** + * 递归法(求深度法) + */ + //定义最大深度 + int maxnum = 0; + + public int maxDepth(TreeNode root) { + ans(root,0); + return maxnum; + } + + //递归求解最大深度 + void ans(TreeNode tr,int tmp){ + if(tr==null) return; + tmp++; + maxnum = maxnum