Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
youngyangyang04 committed May 22, 2022
1 parent 28a8d2e commit 278011c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 60 deletions.
4 changes: 2 additions & 2 deletions problems/0056.合并区间.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public:
};
```

* 时间复杂度:$O(n\log n)$ ,有一个快排
* 空间复杂度:$O(1)$,我没有算result数组(返回值所需容器占的空间)
* 时间复杂度:O(nlog n) ,有一个快排
* 空间复杂度:O(n),有一个快排,最差情况(倒序)时,需要n次递归调用。因此确实需要O(n)的栈空间


## 总结
Expand Down
25 changes: 13 additions & 12 deletions problems/0077.组合.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

也可以直接看我的B站视频:[带你学透回溯算法-组合问题(对应力扣题目:77.组合)](https://www.bilibili.com/video/BV1ti4y1L7cv#reply3733925949)

# 思路
## 思路


本题这是回溯法的经典题目。
Expand Down Expand Up @@ -232,7 +232,7 @@ void backtracking(参数) {

**对比一下本题的代码,是不是发现有点像!** 所以有了这个模板,就有解题的大体方向,不至于毫无头绪。

# 总结
## 总结

组合问题是回溯法解决的经典问题,我们开始的时候给大家列举一个很形象的例子,就是n为100,k为50的话,直接想法就需要50层for循环。

Expand All @@ -242,7 +242,7 @@ void backtracking(参数) {

接着用回溯法三部曲,逐步分析了函数参数、终止条件和单层搜索的过程。

# 剪枝优化
## 剪枝优化

我们说过,回溯法虽然是暴力搜索,但也有时候可以有点剪枝优化一下的。

Expand Down Expand Up @@ -324,7 +324,7 @@ public:
};
```

# 剪枝总结
## 剪枝总结

本篇我们准对求组合问题的回溯法代码做了剪枝优化,这个优化如果不画图的话,其实不好理解,也不好讲清楚。

Expand All @@ -334,10 +334,10 @@ public:



# 其他语言版本
## 其他语言版本


## Java:
### Java:
```java
class Solution {
List<List<Integer>> result = new ArrayList<>();
Expand Down Expand Up @@ -366,6 +366,8 @@ class Solution {
}
```

### Python

Python2:
```python
class Solution(object):
Expand Down Expand Up @@ -395,7 +397,6 @@ class Solution(object):
return result
```

## Python
```python
class Solution:
def combine(self, n: int, k: int) -> List[List[int]]:
Expand Down Expand Up @@ -432,7 +433,7 @@ class Solution:
```


## javascript
### javascript

剪枝:
```javascript
Expand All @@ -456,7 +457,7 @@ const combineHelper = (n, k, startIndex) => {
}
```

## TypeScript
### TypeScript

```typescript
function combine(n: number, k: number): number[][] {
Expand All @@ -479,7 +480,7 @@ function combine(n: number, k: number): number[][] {



## Go
### Go
```Go
var res [][]int
func combine(n int, k int) [][]int {
Expand Down Expand Up @@ -534,7 +535,7 @@ func backtrack(n,k,start int,track []int){
}
```

## C
### C
```c
int* path;
int pathTop;
Expand Down Expand Up @@ -642,7 +643,7 @@ int** combine(int n, int k, int* returnSize, int** returnColumnSizes){
}
```

## Swift
### Swift

```swift
func combine(_ n: Int, _ k: Int) -> [[Int]] {
Expand Down
4 changes: 2 additions & 2 deletions problems/0101.对称二叉树.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public:
};
```
# 总结
## 总结
这次我们又深度剖析了一道二叉树的“简单题”,大家会发现,真正的把题目搞清楚其实并不简单,leetcode上accept了和真正掌握了还是有距离的。
Expand All @@ -248,7 +248,7 @@ public:
如果已经做过这道题目的同学,读完文章可以再去看看这道题目,思考一下,会有不一样的发现!
# 相关题目推荐
## 相关题目推荐
这两道题目基本和本题是一样的,只要稍加修改就可以AC。
Expand Down
2 changes: 1 addition & 1 deletion problems/0435.无重叠区间.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public:
};
```
* 时间复杂度:O(nlog n) ,有一个快排
* 空间复杂度:O(1)
* 空间复杂度:O(n),有一个快排,最差情况(倒序)时,需要n次递归调用。因此确实需要O(n)的栈空间
大家此时会发现如此复杂的一个问题,代码实现却这么简单!
Expand Down
4 changes: 2 additions & 2 deletions problems/0452.用最少数量的箭引爆气球.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public:
};
```

* 时间复杂度:$O(n\log n)$,因为有一个快排
* 空间复杂度:$O(1)$
* 时间复杂度:O(nlog n),因为有一个快排
* 空间复杂度:O(1),有一个快排,最差情况(倒序)时,需要n次递归调用。因此确实需要O(n)的栈空间

可以看出代码并不复杂。

Expand Down
41 changes: 0 additions & 41 deletions problems/面试题 02.07. 解法更新.md

This file was deleted.

0 comments on commit 278011c

Please sign in to comment.