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

[pull] master from youngyangyang04:master #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 4 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Oct 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 0104.二叉树的最大深度.md
104二叉树最大深度贡献java版本的从深度角度的递归法
  • Loading branch information
Tcotyledons authored Sep 29, 2022
commit de017e95441ece804182aec87cfba7f4414cc4a7
25 changes: 25 additions & 0 deletions problems/0104.二叉树的最大深度.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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<tmp?tmp:maxnum;
ans(tr.left,tmp);
ans(tr.right,tmp);
tmp--;
}
}
```

```java
class solution {
/**
Expand Down

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