From bf6c4e7f7b3c8f118960362ab735f8e4977e0e58 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Fri, 21 Jul 2023 17:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200112.=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=80=BB=E5=92=8C=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0112.路径总和.md | 75 ++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index 39285a3b..240462b6 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -21,9 +21,9 @@ 返回 true, 因为存在目标和为 22 的根节点到叶子节点的路径 5->4->11->2。 -## 视频讲解 +## 算法公开课 -**《代码随想录》算法视频公开课:[拿不准的遍历顺序,搞不清的回溯过程,我太难了! | LeetCode:112. 路径总和](https://www.bilibili.com/video/BV19t4y1L7CR),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[拿不准的遍历顺序,搞不清的回溯过程,我太难了! | LeetCode:112. 路径总和](https://www.bilibili.com/video/BV19t4y1L7CR),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -32,8 +32,8 @@ 那么接下来我通过详细讲解如下两道题,来回答这个问题: -* 112.路径总和 -* 113.路径总和ii +* [112.路径总和](https://leetcode.cn/problems/path-sum/) +* [113.路径总和ii](https://leetcode.cn/problems/path-sum-ii/) 这道题我们要遍历从根节点到叶子节点的路径看看总和是不是目标和。 @@ -218,7 +218,9 @@ public: 如果大家完全理解了本题的递归方法之后,就可以顺便把leetcode上113. 路径总和ii做了。 -# 113. 路径总和ii +## 相关题目推荐 + +### 113. 路径总和ii [力扣题目链接](https://leetcode.cn/problems/path-sum-ii/) @@ -232,7 +234,7 @@ public: ![113.路径总和ii1.png](https://code-thinking-1253855093.file.myqcloud.com/pics/20210203160854654.png) -## 思路 +### 思路 113.路径总和ii要遍历整个树,找到所有路径,**所以递归函数不要返回值!** @@ -289,7 +291,7 @@ public: 至于113. 路径总和ii 的迭代法我并没有写,用迭代方式记录所有路径比较麻烦,也没有必要,如果大家感兴趣的话,可以再深入研究研究。 -## 总结 +### 总结 本篇通过leetcode上112. 路径总和 和 113. 路径总和ii 详细的讲解了 递归函数什么时候需要返回值,什么不需要返回值。 @@ -300,11 +302,11 @@ public: -# 其他语言版本 +## 其他语言版本 -## java +### Java -### 0112.路径总和 +#### 0112.路径总和 ```java class solution { @@ -422,7 +424,7 @@ class solution { } ``` -### 0113.路径总和-ii +#### 0113.路径总和-ii ```java class solution { @@ -529,9 +531,9 @@ class Solution { } ``` -## python +### Python -### 0112.路径总和 +#### 0112.路径总和 (版本一) 递归 ```python @@ -618,7 +620,7 @@ class Solution: -### 0113.路径总和-ii +#### 0113.路径总和-ii (版本一) 递归 ```python @@ -719,9 +721,9 @@ class Solution: ``` -## go +### Go -### 112. 路径总和 +#### 112. 路径总和 ```go //递归法 @@ -746,7 +748,7 @@ func hasPathSum(root *TreeNode, targetSum int) bool { } ``` -### 113. 路径总和 II +#### 113. 路径总和 II ```go /** @@ -786,9 +788,9 @@ func traverse(node *TreeNode, result *[][]int, currPath *[]int, targetSum int) { } ``` -## javascript +### Javascript -### 0112.路径总和 +#### 0112.路径总和 **递归** @@ -852,7 +854,7 @@ let hasPathSum = function(root, targetSum) { }; ``` -### 0113.路径总和-ii +#### 0113.路径总和-ii **递归** @@ -950,9 +952,9 @@ let pathSum = function(root, targetSum) { }; ``` -## TypeScript +### TypeScript -### 0112.路径总和 +#### 0112.路径总和 **递归法:** @@ -1034,7 +1036,7 @@ function hasPathSum(root: TreeNode | null, targetSum: number): boolean { }; ``` -### 0112.路径总和 ii +#### 0112.路径总和 ii **递归法:** @@ -1070,9 +1072,9 @@ function pathSum(root: TreeNode | null, targetSum: number): number[][] { }; ``` -## Swift +### Swift -### 0112.路径总和 +#### 0112.路径总和 **递归** @@ -1141,7 +1143,7 @@ func hasPathSum(_ root: TreeNode?, _ targetSum: Int) -> Bool { } ``` -### 0113.路径总和 II +#### 0113.路径总和 II **递归** @@ -1192,10 +1194,10 @@ func traversal(_ cur: TreeNode?, count: Int) { } ``` -## C +### C -> 0112.路径总和 -> 递归法: +#### 0112.路径总和 +递归法: ```c bool hasPathSum(struct TreeNode* root, int targetSum){ @@ -1252,7 +1254,7 @@ bool hasPathSum(struct TreeNode* root, int targetSum){ } ``` -> 0113.路径总和 II +#### 0113.路径总和 II ```c int** ret; @@ -1317,9 +1319,9 @@ int** pathSum(struct TreeNode* root, int targetSum, int* returnSize, int** retur } ``` -## Scala +### Scala -### 0112.路径总和 +#### 0112.路径总和 **递归:** @@ -1369,7 +1371,7 @@ object Solution { } ``` -### 0113.路径总和 II +#### 0113.路径总和 II **递归:** @@ -1405,9 +1407,9 @@ object Solution { } ``` -## rust +### Rust -### 112.路径总和.md +#### 0112.路径总和 递归: @@ -1461,7 +1463,7 @@ impl Solution { } ``` -### 113.路径总和-ii +#### 0113.路径总和-ii ```rust impl Solution { @@ -1514,3 +1516,4 @@ impl Solution { +