From fe9323900758c0f056299728d1551ab57d1efab3 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Fri, 21 Jul 2023 18:00:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200106.=E4=BB=8E=E4=B8=AD?= =?UTF-8?q?=E5=BA=8F=E4=B8=8E=E5=90=8E=E5=BA=8F=E9=81=8D=E5=8E=86=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E6=9E=84=E9=80=A0=E4=BA=8C=E5=8F=89=E6=A0=91=20?= =?UTF-8?q?=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...序与后序遍历序列构造二叉树.md | 40 +++++++++---------- problems/0112.路径总和.md | 38 +++++++++--------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md index a0bab999..0144fc5c 100644 --- a/problems/0106.从中序与后序遍历序列构造二叉树.md +++ b/problems/0106.从中序与后序遍历序列构造二叉树.md @@ -29,9 +29,9 @@ ![106. 从中序与后序遍历序列构造二叉树1](https://code-thinking-1253855093.file.myqcloud.com/pics/20210203154316774.png) -# 视频讲解 +## 算法公开课 -**《代码随想录》算法视频公开课:[坑很多!来看看你掉过几次坑 | LeetCode:106.从中序与后序遍历序列构造二叉树](https://www.bilibili.com/video/BV1vW4y1i7dn),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[坑很多!来看看你掉过几次坑 | LeetCode:106.从中序与后序遍历序列构造二叉树](https://www.bilibili.com/video/BV1vW4y1i7dn),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -158,8 +158,6 @@ root->right = traversal(rightInorder, rightPostorder); 完整代码如下: -### C++完整代码 - ```CPP class Solution { private: @@ -281,8 +279,6 @@ public: 下面给出用下标索引写出的代码版本:(思路是一样的,只不过不用重复定义vector了,每次用下标索引来分割) -### C++优化版本 - ```CPP class Solution { private: @@ -400,8 +396,9 @@ public: }; ``` +## 相关题目推荐 -# 105.从前序与中序遍历序列构造二叉树 +### 105.从前序与中序遍历序列构造二叉树 [力扣题目链接](https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) @@ -418,7 +415,7 @@ public: ![105. 从前序与中序遍历序列构造二叉树](https://code-thinking-1253855093.file.myqcloud.com/pics/20210203154626672.png) -## 思路 +### 思路 本题和106是一样的道理。 @@ -547,7 +544,7 @@ public: }; ``` -# 思考题 +## 思考题 前序和中序可以唯一确定一棵二叉树。 @@ -569,7 +566,7 @@ tree2 的前序遍历是[1 2 3], 后序遍历是[3 2 1]。 所以前序和后序不能唯一确定一棵二叉树! -# 总结 +## 总结 之前我们讲的二叉树题目都是各种遍历二叉树,这次开始构造二叉树了,思路其实比较简单,但是真正代码实现出来并不容易。 @@ -585,9 +582,9 @@ tree2 的前序遍历是[1 2 3], 后序遍历是[3 2 1]。 -# 其他语言版本 +## 其他语言版本 -## Java +### Java 106.从中序与后序遍历序列构造二叉树 @@ -688,7 +685,7 @@ class Solution { } ``` -## Python +### Python 105.从前序与中序遍历序列构造二叉树 @@ -754,7 +751,7 @@ class Solution: return root ``` -## Go +### Go 106 从中序与后序遍历序列构造二叉树 @@ -833,9 +830,7 @@ func build(pre []int, in []int, root int, l, r int) *TreeNode { ``` - - -## JavaScript +### JavaScript ```javascript var buildTree = function(inorder, postorder) { @@ -863,7 +858,7 @@ var buildTree = function(preorder, inorder) { }; ``` -## TypeScript +### TypeScript > 106.从中序与后序遍历序列构造二叉树 @@ -969,7 +964,7 @@ function buildTree(preorder: number[], inorder: number[]): TreeNode | null { }; ``` -## C +### C 106 从中序与后序遍历序列构造二叉树 @@ -1047,7 +1042,7 @@ struct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder, int in } ``` -## Swift +### Swift 105 从前序与中序遍历序列构造二叉树 @@ -1140,7 +1135,7 @@ class Solution_0106 { } ``` -## Scala +### Scala 106 从中序与后序遍历序列构造二叉树 @@ -1188,7 +1183,7 @@ object Solution { } ``` -## rust +### Rust 106 从中序与后序遍历序列构造二叉树 @@ -1238,3 +1233,4 @@ impl Solution { + diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index 240462b6..be03f719 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -306,7 +306,7 @@ public: ### Java -#### 0112.路径总和 +0112.路径总和 ```java class solution { @@ -424,7 +424,7 @@ class solution { } ``` -#### 0113.路径总和-ii +0113.路径总和-ii ```java class solution { @@ -533,7 +533,7 @@ class Solution { ### Python -#### 0112.路径总和 +0112.路径总和 (版本一) 递归 ```python @@ -620,7 +620,7 @@ class Solution: -#### 0113.路径总和-ii +0113.路径总和-ii (版本一) 递归 ```python @@ -723,7 +723,7 @@ class Solution: ``` ### Go -#### 112. 路径总和 +112. 路径总和 ```go //递归法 @@ -748,7 +748,7 @@ func hasPathSum(root *TreeNode, targetSum int) bool { } ``` -#### 113. 路径总和 II +113. 路径总和 II ```go /** @@ -790,7 +790,7 @@ func traverse(node *TreeNode, result *[][]int, currPath *[]int, targetSum int) { ### Javascript -#### 0112.路径总和 +0112.路径总和 **递归** @@ -854,7 +854,7 @@ let hasPathSum = function(root, targetSum) { }; ``` -#### 0113.路径总和-ii +0113.路径总和-ii **递归** @@ -954,7 +954,7 @@ let pathSum = function(root, targetSum) { ### TypeScript -#### 0112.路径总和 +0112.路径总和 **递归法:** @@ -1036,7 +1036,7 @@ function hasPathSum(root: TreeNode | null, targetSum: number): boolean { }; ``` -#### 0112.路径总和 ii +0112.路径总和 ii **递归法:** @@ -1074,7 +1074,7 @@ function pathSum(root: TreeNode | null, targetSum: number): number[][] { ### Swift -#### 0112.路径总和 +0112.路径总和 **递归** @@ -1143,7 +1143,7 @@ func hasPathSum(_ root: TreeNode?, _ targetSum: Int) -> Bool { } ``` -#### 0113.路径总和 II +0113.路径总和 II **递归** @@ -1196,7 +1196,8 @@ func traversal(_ cur: TreeNode?, count: Int) { ### C -#### 0112.路径总和 +0112.路径总和 + 递归法: ```c @@ -1254,7 +1255,7 @@ bool hasPathSum(struct TreeNode* root, int targetSum){ } ``` -#### 0113.路径总和 II +0113.路径总和 II ```c int** ret; @@ -1321,7 +1322,7 @@ int** pathSum(struct TreeNode* root, int targetSum, int* returnSize, int** retur ### Scala -#### 0112.路径总和 +0112.路径总和 **递归:** @@ -1371,7 +1372,7 @@ object Solution { } ``` -#### 0113.路径总和 II +0113.路径总和 II **递归:** @@ -1409,7 +1410,7 @@ object Solution { ### Rust -#### 0112.路径总和 +0112.路径总和 递归: @@ -1463,7 +1464,7 @@ impl Solution { } ``` -#### 0113.路径总和-ii +0113.路径总和-ii ```rust impl Solution { @@ -1516,4 +1517,3 @@ impl Solution { -