diff --git "a/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" "b/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" index b74529d638..a7c206afcf 100644 --- "a/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.md" +++ "b/problems/0104.\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.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