更新 0216.组合总和III 排版格式修复

This commit is contained in:
jinbudaily
2023-07-24 11:08:32 +08:00
parent f5e50a919d
commit f30fd2982b
2 changed files with 18 additions and 19 deletions

View File

@ -103,7 +103,7 @@ for (int i = 1; i <= n; i++) {
在[关于回溯算法,你该了解这些!](https://programmercarl.com/回溯算法理论基础.html)中我们提到了回溯法三部曲,那么我们按照回溯法三部曲开始正式讲解代码了。
## 回溯法三部曲
### 回溯法三部曲
* 递归函数的返回值以及参数
@ -744,3 +744,4 @@ object Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -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]]
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[和组合问题有啥区别?回溯算法如何剪枝?| LeetCode216.组合总和III](https://www.bilibili.com/video/BV1wg411873x),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[和组合问题有啥区别?回溯算法如何剪枝?| LeetCode216.组合总和III](https://www.bilibili.com/video/BV1wg411873x),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
## 思路
本题就是在[1,2,3,4,5,6,7,8,9]这个集合中找到和为n的k个数的组合。
@ -54,7 +52,7 @@
图中可以看出只有最后取到集合13和为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 {