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
Show file tree
Hide file tree
Changes from all commits
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
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
4 changes: 4 additions & 0 deletions problems/0129.求根到叶子节点数字之和.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,11 @@ TypeScript:
```typescript
function sumNumbers(root: TreeNode | null): number {
if (root === null) return 0;
// 记录最终结果
let resTotal: number = 0;
// 记录路径中遇到的节点值
const route: number[] = [];
// 递归初始值
route.push(root.val);
recur(root, route);
return resTotal;
Expand All @@ -342,6 +345,7 @@ function sumNumbers(root: TreeNode | null): number {
};
}
function listToSum(nums: number[]): number {
// 数组求和
return Number(nums.join(''));
}
};
Expand Down

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