diff --git a/problems/0077.组合.md b/problems/0077.组合.md index 702ffafe..7d71b517 100644 --- a/problems/0077.组合.md +++ b/problems/0077.组合.md @@ -103,7 +103,7 @@ for (int i = 1; i <= n; i++) { 在[关于回溯算法,你该了解这些!](https://programmercarl.com/回溯算法理论基础.html)中我们提到了回溯法三部曲,那么我们按照回溯法三部曲开始正式讲解代码了。 -## 回溯法三部曲 +### 回溯法三部曲 * 递归函数的返回值以及参数 @@ -744,3 +744,4 @@ object Solution { + diff --git a/problems/0216.组合总和III.md b/problems/0216.组合总和III.md index 319b2eba..4de7dc58 100644 --- a/problems/0216.组合总和III.md +++ b/problems/0216.组合总和III.md @@ -7,8 +7,6 @@ - - > 别看本篇选的是组合总和III,而不是组合总和,本题和上一篇77.组合相比难度刚刚好! # 216.组合总和III @@ -30,12 +28,12 @@ 输入: k = 3, n = 9 输出: [[1,2,6], [1,3,5], [2,3,4]] -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[和组合问题有啥区别?回溯算法如何剪枝?| LeetCode:216.组合总和III](https://www.bilibili.com/video/BV1wg411873x),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[和组合问题有啥区别?回溯算法如何剪枝?| LeetCode:216.组合总和III](https://www.bilibili.com/video/BV1wg411873x),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 -# 思路 +## 思路 本题就是在[1,2,3,4,5,6,7,8,9]这个集合中找到和为n的k个数的组合。 @@ -54,7 +52,7 @@ 图中,可以看出,只有最后取到集合(1,3)和为4 符合条件。 -## 回溯三部曲 +### 回溯三部曲 * **确定递归函数参数** @@ -165,7 +163,7 @@ public: }; ``` -## 剪枝 +### 剪枝 这道题目,剪枝操作其实是很容易想到了,想必大家看上面的树形图的时候已经想到了。 @@ -238,7 +236,7 @@ public: * 时间复杂度: O(n * 2^n) * 空间复杂度: O(n) -# 总结 +## 总结 开篇就介绍了本题与[77.组合](https://programmercarl.com/0077.组合.html)的区别,相对来说加了元素总和的限制,如果做完[77.组合](https://programmercarl.com/0077.组合.html)再做本题在合适不过。 @@ -249,10 +247,10 @@ public: -# 其他语言版本 +## 其他语言版本 -## Java +### Java 模板方法 @@ -358,7 +356,7 @@ class Solution { } ``` -## Python +### Python ```py class Solution: @@ -383,7 +381,7 @@ class Solution: ``` -## Go +### Go 回溯+减枝 @@ -418,7 +416,7 @@ func dfs(k, n int, start int, sum int) { } ``` -## javaScript +### JavaScript ```js /** @@ -455,7 +453,7 @@ var combinationSum3 = function(k, n) { }; ``` -## TypeScript +### TypeScript ```typescript function combinationSum3(k: number, n: number): number[][] { @@ -479,7 +477,7 @@ function combinationSum3(k: number, n: number): number[][] { }; ``` -## Rust +### Rust ```Rust impl Solution { @@ -516,7 +514,7 @@ impl Solution { } ``` -## C +### C ```c int* path; @@ -575,7 +573,7 @@ int** combinationSum3(int k, int n, int* returnSize, int** returnColumnSizes){ } ``` -## Swift +### Swift ```swift func combinationSum3(_ count: Int, _ targetSum: Int) -> [[Int]] { @@ -607,7 +605,7 @@ func combinationSum3(_ count: Int, _ targetSum: Int) -> [[Int]] { } ``` -## Scala +### Scala ```scala object Solution {