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 #312

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 20 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a9039c0
更新 404.左叶子之和 排版格式修复
jinbudaily Jul 21, 2023
f3a3701
更新 513.找树左下角的值 排版格式修复
jinbudaily Jul 21, 2023
bf6c4e7
更新 0112.路径总和 排版格式修复
jinbudaily Jul 21, 2023
fe93239
更新 0106.从中序与后序遍历序列构造二叉树 排版格式修复
jinbudaily Jul 21, 2023
b4eefe9
更新 0654.最大二叉树 排版格式修复
jinbudaily Jul 21, 2023
eadc704
更新 0617.合并二叉树 排版格式修复
jinbudaily Jul 21, 2023
ac239bc
更新 0700.二叉搜索树中的搜索 排版格式修复
jinbudaily Jul 21, 2023
7746734
更新 0098.验证二叉搜索树 排版格式修复
jinbudaily Jul 21, 2023
74bbca2
更新 0530.二叉搜索树的最小绝对差 排版格式修复
jinbudaily Jul 21, 2023
55b85b5
更新 0501.二叉搜索树中的众数 排版格式修复
jinbudaily Jul 23, 2023
3a2490b
更新 0236.二叉树的最近公共祖先 排版格式修复
jinbudaily Jul 23, 2023
07e1ccc
更新 0235.二叉搜索树的最近公共祖先 排版格式修复
jinbudaily Jul 23, 2023
7027116
更新 0701.二叉搜索树中的插入操作 排版格式修复
jinbudaily Jul 23, 2023
0f22ada
更新 0450.删除二叉搜索树中的节点 排版格式修复
jinbudaily Jul 23, 2023
e14e216
更新 0669.修剪二叉搜索树 排版格式修复
jinbudaily Jul 23, 2023
572c089
更新 0108.将有序数组转换为二叉搜索树 排版格式修复
jinbudaily Jul 23, 2023
6bf34cd
更新 0538.将二叉搜索树转换为累加树 排版格式修复
jinbudaily Jul 23, 2023
7539060
更新 二叉树总结篇 排版格式修复
jinbudaily Jul 23, 2023
2b6e851
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 23, 2023
dd04907
Merge pull request #2199 from jinbudaily/master
youngyangyang04 Jul 24, 2023
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
Next Next commit
更新 404.左叶子之和 排版格式修复
  • Loading branch information
jinbudaily committed Jul 21, 2023
commit a9039c0d2dd2c625c98009998677b20089b46524
29 changes: 15 additions & 14 deletions problems/0404.左叶子之和.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

![404.左叶子之和1](https://code-thinking-1253855093.file.myqcloud.com/pics/20210204151927654.png)

## 视频讲解
## 算法公开课

**《代码随想录》算法视频公开课:[二叉树的题目中,总有一些规则让你找不到北 | LeetCode:404.左叶子之和](https://www.bilibili.com/video/BV1GY4y1K7z8),相信结合视频在看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)::[二叉树的题目中,总有一些规则让你找不到北 | LeetCode:404.左叶子之和](https://www.bilibili.com/video/BV1GY4y1K7z8),相信结合视频在看本篇题解,更有助于大家对本题的理解**。

## 思路

Expand Down Expand Up @@ -48,7 +48,7 @@ if (node->left != NULL && node->left->left == NULL && node->left->right == NULL)
}
```

## 递归法
### 递归法

递归的遍历顺序为后序遍历(左右中),是因为要通过递归函数的返回值来累加求取左叶子数值之和。

Expand Down Expand Up @@ -131,11 +131,11 @@ public:
return leftValue + sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);
}
};
```
```

精简之后的代码其实看不出来用的是什么遍历方式了,对于算法初学者以上根据第一个版本来学习。

## 迭代法
### 迭代法

本题迭代法使用前中后序都是可以的,只要把左叶子节点统计出来,就可以了,那么参考文章 [二叉树:听说递归能做的,栈也能做!](https://programmercarl.com/二叉树的迭代遍历.html)和[二叉树:迭代法统一写法](https://programmercarl.com/二叉树的统一迭代法.html)中的写法,可以写出一个前序遍历的迭代法。

Expand Down Expand Up @@ -177,7 +177,7 @@ public:

## 其他语言版本

### Java
### Java:

**递归**

Expand Down Expand Up @@ -246,7 +246,7 @@ class Solution {
```


### Python
### Python:
递归
```python
# Definition for a binary tree node.
Expand Down Expand Up @@ -316,7 +316,7 @@ class Solution:

```

### Go
### Go:

**递归法**

Expand Down Expand Up @@ -368,7 +368,7 @@ func sumOfLeftLeaves(root *TreeNode) int {
```


### JavaScript
### JavaScript:

**递归法**

Expand Down Expand Up @@ -417,7 +417,7 @@ var sumOfLeftLeaves = function(root) {
};
```

### TypeScript
### TypeScript:

> 递归法

Expand Down Expand Up @@ -462,7 +462,7 @@ function sumOfLeftLeaves(root: TreeNode | null): number {
};
```

### Swift
### Swift:

**递归法**
```swift
Expand Down Expand Up @@ -511,7 +511,7 @@ func sumOfLeftLeaves(_ root: TreeNode?) -> Int {
}
```

### C
### C:
递归法:
```c
int sumOfLeftLeaves(struct TreeNode* root){
Expand Down Expand Up @@ -561,7 +561,7 @@ int sumOfLeftLeaves(struct TreeNode* root){
}
```

### Scala
### Scala:

**递归:**
```scala
Expand Down Expand Up @@ -600,7 +600,7 @@ object Solution {
}
```

### Rust
### Rust:

**递归**

Expand Down Expand Up @@ -656,3 +656,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

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