更新 0111.二叉树的最小深度 排版格式修复

This commit is contained in:
jinbudaily
2023-07-21 15:03:31 +08:00
parent 4e77ae6450
commit 600a42730c

View File

@ -26,9 +26,11 @@
返回它的最小深度 2.
# 思路
## 算法公开课
《代码随想录》算法视频公开课:[看起来好像做过,一写就错! | LeetCode111.二叉树的最小深度](https://www.bilibili.com/video/BV1QD4y1B7e2),相信结合视频看本篇题解,更有助于大家对本题的理解。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[看起来好像做过,一写就错! | LeetCode111.二叉树的最小深度](https://www.bilibili.com/video/BV1QD4y1B7e2),相信结合视频看本篇题解,更有助于大家对本题的理解**
## 思路
看完了这篇[104.二叉树的最大深度](https://programmercarl.com/0104.二叉树的最大深度.html),再来看看如何求最小深度。
@ -52,7 +54,7 @@
什么是叶子节点,左右孩子都为空的节点才是叶子节点!
## 递归法
### 递归法
来来来,一起递归三部曲:
@ -199,7 +201,7 @@ public:
};
```
## 迭代法
### 迭代法
相对于[104.二叉树的最大深度](https://programmercarl.com/0104.二叉树的最大深度.html),本题还可以使用层序遍历的方式来解决,思路是一样的。
@ -237,10 +239,10 @@ public:
```
# 其他语言版本
## 其他语言版本
## Java
### Java:
```Java
class Solution {
@ -300,7 +302,7 @@ class Solution {
}
```
## Python
### Python :
递归法(版本一)
@ -400,9 +402,7 @@ class Solution:
return depth
```
## Go
### Go:
```go
/**
@ -463,7 +463,7 @@ func minDepth(root *TreeNode) int {
```
## JavaScript
### JavaScript:
递归法:
@ -509,7 +509,7 @@ var minDepth = function(root) {
};
```
## TypeScript
### TypeScript:
> 递归法
@ -547,7 +547,7 @@ function minDepth(root: TreeNode | null): number {
};
```
## Swift
### Swift:
> 递归
```Swift
@ -594,7 +594,7 @@ func minDepth(_ root: TreeNode?) -> Int {
```
## Scala
### Scala:
递归法:
```scala
@ -633,7 +633,8 @@ object Solution {
}
```
rust:
### Rust:
```rust
impl Solution {
// 递归