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

This commit is contained in:
jinbudaily
2023-07-24 11:15:23 +08:00
parent 87b215dd2e
commit 2ed8beef41

View File

@ -39,11 +39,11 @@ candidates 中的数字可以无限制重复被选取。
[3,5]
]
# 算法公开课
## 算法公开课
**《代码随想录》算法视频公开课:[Leetcode:39. 组合总和讲解](https://www.bilibili.com/video/BV1KT4y1M7HJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[Leetcode:39. 组合总和讲解](https://www.bilibili.com/video/BV1KT4y1M7HJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
# 思路
## 思路
题目中的**无限制重复被选取,吓得我赶紧想想 出现0 可咋办**然后看到下面提示1 <= candidates[i] <= 200我就放心了。
@ -57,7 +57,7 @@ candidates 中的数字可以无限制重复被选取。
而在[77.组合](https://programmercarl.com/0077.组合.html)和[216.组合总和III](https://programmercarl.com/0216.组合总和III.html) 中都可以知道要递归K层因为要取k个元素的组合。
## 回溯三部曲
### 回溯三部曲
* 递归函数参数
@ -156,7 +156,7 @@ public:
};
```
## 剪枝优化
### 剪枝优化
在这个树形结构中:
@ -217,7 +217,7 @@ public:
* 时间复杂度: O(n * 2^n),注意这只是复杂度的上界,因为剪枝的存在,真实的时间复杂度远小于此
* 空间复杂度: O(target)
# 总结
## 总结
本题和我们之前讲过的[77.组合](https://programmercarl.com/0077.组合.html)、[216.组合总和III](https://programmercarl.com/0216.组合总和III.html)有两点不同:
@ -238,10 +238,10 @@ public:
# 其他语言版本
## 其他语言版本
## Java
### Java
```Java
// 剪枝优化
@ -271,7 +271,7 @@ class Solution {
}
```
## Python
### Python
回溯(版本一)
@ -370,7 +370,7 @@ class Solution:
```
## Go
### Go
主要在于递归中传递下一个数字
@ -404,7 +404,7 @@ func dfs(candidates []int, start int, target int) {
}
```
## JavaScript
### JavaScript
```js
var combinationSum = function(candidates, target) {
@ -430,7 +430,7 @@ var combinationSum = function(candidates, target) {
};
```
## TypeScript
### TypeScript
```typescript
function combinationSum(candidates: number[], target: number): number[][] {
@ -456,7 +456,7 @@ function combinationSum(candidates: number[], target: number): number[][] {
};
```
## Rust
### Rust
```Rust
impl Solution {
@ -485,7 +485,7 @@ impl Solution {
}
```
## C
### C
```c
int* path;
@ -541,7 +541,7 @@ int** combinationSum(int* candidates, int candidatesSize, int target, int* retur
}
```
## Swift
### Swift
```swift
func combinationSum(_ candidates: [Int], _ target: Int) -> [[Int]] {
@ -570,7 +570,7 @@ func combinationSum(_ candidates: [Int], _ target: Int) -> [[Int]] {
}
```
## Scala
### Scala
```scala
object Solution {
@ -604,3 +604,4 @@ object Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>