更新 二叉树的递归遍历 排版格式修复

This commit is contained in:
jinbudaily
2023-07-20 15:53:16 +08:00
parent c6bcd423d6
commit 7807b5e798

View File

@ -4,15 +4,15 @@
</a>
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
> 一看就会,一写就废!
# 二叉树的递归遍历
## 算法公开课
《代码随想录》算法视频公开课:[每次写递归都要靠直觉? 这次带你学透二叉树的递归遍历!](https://www.bilibili.com/video/BV1Wh411S7xt),相信结合视频看本篇题解,更有助于大家对本题的理解。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[每次写递归都要靠直觉? 这次带你学透二叉树的递归遍历!](https://www.bilibili.com/video/BV1Wh411S7xt),相信结合视频看本篇题解,更有助于大家对本题的理解**
> 一看就会,一写就废!
## 思路
这次我们要好好谈一谈递归,为什么很多同学看递归算法都是“一看就会,一写就废”。
@ -109,14 +109,10 @@ void traversal(TreeNode* cur, vector<int>& vec) {
可能有同学感觉前后中序遍历的递归太简单了,要打迭代法(非递归),别急,我们明天打迭代法,打个通透!
## 其他语言版本
### Java
# 其他语言版本
Java
```Java
// 前序遍历·递归·LC144_二叉树的前序遍历
class Solution {
@ -171,7 +167,8 @@ class Solution {
}
```
Python
### Python
```python
# 前序遍历-递归-LC144_二叉树的前序遍历
# Definition for a binary tree node.
@ -219,7 +216,7 @@ class Solution:
return left + right + [root.val]
```
Go
### Go
前序遍历:
```go
@ -273,7 +270,7 @@ func postorderTraversal(root *TreeNode) (res []int) {
}
```
Javascript版本
### Javascript
前序遍历:
```Javascript
@ -327,7 +324,7 @@ var postorderTraversal = function(root) {
};
```
TypeScript:
### TypeScript:
```typescript
// 前序遍历
@ -370,7 +367,7 @@ function postorderTraversal(node: TreeNode | null): number[] {
}
```
C:
### C:
```c
//前序遍历:
@ -422,8 +419,9 @@ int* postorderTraversal(struct TreeNode* root, int* returnSize){
}
```
Swift:
### Swift:
前序遍历144.二叉树的前序遍历)
```Swift
func preorderTraversal(_ root: TreeNode?) -> [Int] {
var res = [Int]()
@ -473,7 +471,10 @@ func postorder(_ root: TreeNode?, res: inout [Int]) {
res.append(root!.val)
}
```
Scala: 前序遍历144.二叉树的前序遍历)
### Scala:
前序遍历144.二叉树的前序遍历)
```scala
object Solution {
import scala.collection.mutable.ListBuffer
@ -525,7 +526,7 @@ object Solution {
}
```
rust:
### Rust:
```rust
use std::cell::RefCell;