Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b57842d

Browse files
Merge branch 'youngyangyang04:master' into master
2 parents 3de2992 + 0c220c5 commit b57842d

7 files changed

+44
-60
lines changed

‎problems/0056.合并区间.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public:
112112
};
113113
```
114114

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

118118

119119
## 总结

‎problems/0077.组合.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

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

30-
# 思路
30+
## 思路
3131

3232

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

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

235-
# 总结
235+
## 总结
236236

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

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

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

245-
# 剪枝优化
245+
## 剪枝优化
246246

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

@@ -324,7 +324,7 @@ public:
324324
};
325325
```
326326

327-
# 剪枝总结
327+
## 剪枝总结
328328

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

@@ -334,10 +334,10 @@ public:
334334

335335

336336

337-
# 其他语言版本
337+
## 其他语言版本
338338

339339

340-
## Java:
340+
### Java:
341341
```java
342342
class Solution {
343343
List<List<Integer>> result = new ArrayList<>();
@@ -366,6 +366,8 @@ class Solution {
366366
}
367367
```
368368

369+
### Python
370+
369371
Python2:
370372
```python
371373
class Solution(object):
@@ -395,7 +397,6 @@ class Solution(object):
395397
return result
396398
```
397399

398-
## Python
399400
```python
400401
class Solution:
401402
def combine(self, n: int, k: int) -> List[List[int]]:
@@ -432,7 +433,7 @@ class Solution:
432433
```
433434

434435

435-
## javascript
436+
### javascript
436437

437438
剪枝:
438439
```javascript
@@ -456,7 +457,7 @@ const combineHelper = (n, k, startIndex) => {
456457
}
457458
```
458459

459-
## TypeScript
460+
### TypeScript
460461

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

480481

481482

482-
## Go
483+
### Go
483484
```Go
484485
var res [][]int
485486
func combine(n int, k int) [][]int {
@@ -534,7 +535,7 @@ func backtrack(n,k,start int,track []int){
534535
}
535536
```
536537

537-
## C
538+
### C
538539
```c
539540
int* path;
540541
int pathTop;
@@ -642,7 +643,7 @@ int** combine(int n, int k, int* returnSize, int** returnColumnSizes){
642643
}
643644
```
644645

645-
## Swift
646+
### Swift
646647

647648
```swift
648649
func combine(_ n: Int, _ k: Int) -> [[Int]] {

‎problems/0101.对称二叉树.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public:
238238
};
239239
```
240240
241-
# 总结
241+
## 总结
242242
243243
这次我们又深度剖析了一道二叉树的"简单题",大家会发现,真正的把题目搞清楚其实并不简单,leetcode上accept了和真正掌握了还是有距离的。
244244
@@ -248,7 +248,7 @@ public:
248248
249249
如果已经做过这道题目的同学,读完文章可以再去看看这道题目,思考一下,会有不一样的发现!
250250
251-
# 相关题目推荐
251+
## 相关题目推荐
252252
253253
这两道题目基本和本题是一样的,只要稍加修改就可以AC。
254254

‎problems/0435.无重叠区间.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public:
9393
};
9494
```
9595
* 时间复杂度:O(nlog n) ,有一个快排
96-
* 空间复杂度:O(1)
96+
* 空间复杂度:O(n),有一个快排,最差情况(倒序)时,需要n次递归调用。因此确实需要O(n)的栈空间
9797
9898
大家此时会发现如此复杂的一个问题,代码实现却这么简单!
9999

‎problems/0452.用最少数量的箭引爆气球.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public:
105105
};
106106
```
107107

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

111111
可以看出代码并不复杂。
112112

‎problems/背包理论基础01背包-2.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,30 @@ function test () {
315315
test();
316316
```
317317

318+
### TypeScript
319+
320+
```typescript
321+
function testWeightBagProblem(
322+
weight: number[],
323+
value: number[],
324+
size: number
325+
): number {
326+
const goodsNum: number = weight.length;
327+
const dp: number[] = new Array(size + 1).fill(0);
328+
for (let i = 0; i < goodsNum; i++) {
329+
for (let j = size; j >= weight[i]; j--) {
330+
dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
331+
}
332+
}
333+
return dp[size];
334+
}
335+
const weight = [1, 3, 4];
336+
const value = [15, 20, 30];
337+
const size = 4;
338+
console.log(testWeightBagProblem(weight, value, size));
339+
340+
```
341+
318342

319343

320344
-----------------------

‎problems/面试题 02.07. 解法更新.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /