Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f438788

Browse files
Merge pull request youngyangyang04#1667 from Tcotyledons/master
Update 0104.二叉树的最大深度.md
2 parents f04dbe8 + de017e9 commit f438788

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎problems/0104.二叉树的最大深度.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,31 @@ class solution {
313313
}
314314
```
315315

316+
```java
317+
class Solution {
318+
/**
319+
* 递归法(求深度法)
320+
*/
321+
//定义最大深度
322+
int maxnum = 0;
323+
324+
public int maxDepth(TreeNode root) {
325+
ans(root,0);
326+
return maxnum;
327+
}
328+
329+
//递归求解最大深度
330+
void ans(TreeNode tr,int tmp){
331+
if(tr==null) return;
332+
tmp++;
333+
maxnum = maxnum<tmp?tmp:maxnum;
334+
ans(tr.left,tmp);
335+
ans(tr.right,tmp);
336+
tmp--;
337+
}
338+
}
339+
```
340+
316341
```java
317342
class solution {
318343
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /