This commit is contained in:
programmercarl
2022-09-22 11:39:53 +08:00
parent 83c4a31098
commit 5a1841aa2b
9 changed files with 65 additions and 55 deletions

View File

@@ -19,13 +19,18 @@
![513.找树左下角的值1](https://img-blog.csdnimg.cn/20210204153017586.png)
# 思路
## 视频讲解
**《代码随想录》算法视频公开课:[怎么找二叉树的左下角? 递归中又带回溯了,怎么办?| LeetCode513.找二叉树左下角的值](https://www.bilibili.com/video/BV1424y1Z7pn),相信结合视频在看本篇题解,更有助于大家对本题的理解**。
## 思路
本地要找出树的最后一行找到最左边的值。此时大家应该想起用层序遍历是非常简单的了,反而用递归的话会比较难一点。
我们依然还是先介绍递归法。
## 递归
### 递归
咋眼一看,这道题目用递归的话就就一直向左遍历,最后一个就是答案呗?
@@ -162,7 +167,7 @@ public:
如果对回溯部分精简的代码 不理解的话,可以看这篇[257. 二叉树的所有路径](https://programmercarl.com/0257.二叉树的所有路径.html)
## 迭代法
### 迭代法
本题使用层序遍历再合适不过了,比递归要好理解的多!
@@ -194,7 +199,7 @@ public:
};
```
# 总结
## 总结
本题涉及如下几点:
@@ -204,10 +209,10 @@ public:
所以本题涉及到的点,我们之前都讲解过,这些知识点需要同学们灵活运用,这样就举一反三了。
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
// 递归法
@@ -264,7 +269,7 @@ class Solution {
## Python
### Python
递归:
```python
@@ -313,7 +318,7 @@ class Solution:
return result
```
## Go
### Go
递归法:
@@ -373,7 +378,7 @@ func findBottomLeftValue(root *TreeNode) int {
}
```
## JavaScript
### JavaScript
递归版本:
@@ -424,7 +429,7 @@ var findBottomLeftValue = function(root) {
};
```
## TypeScript
### TypeScript
> 递归法:
@@ -469,7 +474,7 @@ function findBottomLeftValue(root: TreeNode | null): number {
};
```
## Swift
### Swift
递归版本:
@@ -537,7 +542,7 @@ func findBottomLeftValue(_ root: TreeNode?) -> Int {
}
```
## Scala
### Scala
递归版本:
```scala