Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c01adfa

Browse files
Update
1 parent db295f4 commit c01adfa

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
![算法面试知识大纲](https://img-blog.csdnimg.cn/20200729181420491.png)
1414

15+
# 算法视频讲解
16+
17+
* [KMP算法(理论篇)B站视频](https://www.bilibili.com/video/BV1PD4y1o7nd)
18+
* [KMP算法(代码篇)B站视频](https://www.bilibili.com/video/BV1M5411j7Xx)
19+
* [回溯算法(理论篇)B站视频](https://www.bilibili.com/video/BV1cy4y167mM)
20+
1521
# 算法文章精选
1622

1723
**提示:在电脑端看如下文章的,看不到文章的评论区,建议在手机端「代码随想录」公众号里也翻一下对应的文章,评论区有录友们的打卡总结,相信会和你有不少共鸣!**
@@ -150,6 +156,8 @@
150156
* [本周小结!(回溯算法系列三)](https://mp.weixin.qq.com/s/tLkt9PSo42X60w8i94ViiA)
151157
* [本周小结!(回溯算法系列三)续集](https://mp.weixin.qq.com/s/kSMGHc_YpsqL2j-jb_E_Ag)
152158
* [视频来了!!带你学透回溯算法(理论篇)](https://mp.weixin.qq.com/s/wDd5azGIYWjbU0fdua_qBg)
159+
* [回溯算法:重新安排行程](https://mp.weixin.qq.com/s/3kmbS4qDsa6bkyxR92XCTA)
160+
* [回溯算法:N皇后问题](https://mp.weixin.qq.com/s/lU_QwCMj6g60nh8m98GAWg)
153161

154162

155163
(持续更新中....)
@@ -356,6 +364,7 @@
356364
|[0127.单词接龙](https://github.com/youngyangyang04/leetcode/blob/master/problems/0127.单词接龙.md) |广度优先搜索 |中等|**广度优先搜索**|
357365
|[0129.求根到叶子节点数字之和](https://github.com/youngyangyang04/leetcode/blob/master/problems/0129.求根到叶子节点数字之和.md) |二叉树 |中等|**递归/回溯** 递归里隐藏着回溯,和113.路径总和II类似|
358366
|[0131.分割回文串](https://github.com/youngyangyang04/leetcode/blob/master/problems/0131.分割回文串.md) |回溯 |中等|**回溯**|
367+
|[0135.分发糖果](https://github.com/youngyangyang04/leetcode/blob/master/problems/0135.分发糖果.md) |贪心 |困难|**贪心**好题目|
359368
|[0141.环形链表](https://github.com/youngyangyang04/leetcode/blob/master/problems/0141.环形链表.md) |链表 |简单|**快慢指针/双指针**|
360369
|[0142.环形链表II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0142.环形链表II.md) |链表 |中等|**快慢指针/双指针**|
361370
|[0143.重排链表](https://github.com/youngyangyang04/leetcode/blob/master/problems/0143.重排链表.md) |链表 |中等|**快慢指针/双指针** 也可以用数组,双向队列模拟,考察链表综合操作的好题|

pics/51.N皇后.png

-3.4 KB
Loading

problems/0051.N皇后.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void backtracking(int n, int row, vector<string>& chessboard) {
8989
* 递归终止条件
9090

9191
在如下树形结构中:
92-
![51.N皇后](https://img-blog.csdnimg.cn/20201116173551789.png)
92+
![51.N皇后](https://img-blog.csdnimg.cn/20201117165155239.png)
9393

9494
可以看出,当递归到棋盘最底层(也就是叶子节点)的时候,就可以收集结果并返回了。
9595

problems/0052.N皇后II.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并
3636
class Solution {
3737
private:
3838
int count = 0;
39-
void backtracking(int n, int row, vector<string>& chessboard, vector<vector<string>>& result) {
39+
vector<vector<string>> result;
40+
void backtracking(int n, int row, vector<string>& chessboard) {
4041
if (row == n) {
4142
count++;
4243
return;
4344
}
4445
for (int col = 0; col < n; col++) {
4546
if (isValid(row, col, chessboard, n)) {
4647
chessboard[row][col] = 'Q'; // 放置皇后
47-
backtracking(n, row + 1, chessboard, result);
48+
backtracking(n, row + 1, chessboard);
4849
chessboard[row][col] = '.'; // 回溯
4950
}
5051
}
@@ -74,9 +75,10 @@ bool isValid(int row, int col, vector<string>& chessboard, int n) {
7475
7576
public:
7677
int totalNQueens(int n) {
78+
result.clear();
7779
std::vector<std::string> chessboard(n, std::string(n, '.'));
7880
vector<vector<string>> result;
79-
backtracking(n, 0, chessboard, result);
81+
backtracking(n, 0, chessboard);
8082
return count;
8183
8284
}

problems/0135.分发糖果.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
代码如下:
1313

14-
```
14+
```C++
1515
// 从前向后
1616
for (int i = 1; i < ratings.size(); i++) {
1717
if (ratings[i] > ratings[i - 1]) candyVec[i] = candyVec[i - 1] + 1;
@@ -37,7 +37,7 @@ for (int i = 1; i < ratings.size(); i++) {
3737

3838
所以代码如下:
3939

40-
```
40+
```C++
4141
// 从后向前
4242
for (int i = ratings.size() - 2; i >= 0; i--) {
4343
if (ratings[i] > ratings[i + 1] ) {
@@ -46,21 +46,8 @@ for (int i = ratings.size() - 2; i >= 0; i--) {
4646
}
4747
```
4848

49-
* 将问题分解为若干个子问题
50-
* 找出适合的贪心策略
51-
* 求解每一个子问题的最优解
52-
* 将局部最优解堆叠成全局最优解
53-
54-
* 分解为子问题
55-
56-
57-
58-
这道题目上来也是没什么思路啊
59-
60-
61-
这道题目不好想啊,贪心很巧妙
62-
63-
```
49+
整体代码如下:
50+
```C++
6451
class Solution {
6552
public:
6653
int candy(vector<int>& ratings) {
@@ -81,5 +68,9 @@ public:
8168
return result;
8269
}
8370
};
84-
8571
```
72+
73+
> **我是[程序员Carl](https://github.com/youngyangyang04),[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png)可以找我,本文[leetcode刷题攻略](https://github.com/youngyangyang04/leetcode-master)已收录,更多[精彩算法文章](https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzUxNjY5NTYxNA==&action=getalbum&album_id=1485825793120387074&scene=173#wechat_redirect)尽在:[代码随想录](https://img-blog.csdnimg.cn/20200815195519696.png),关注后就会发现和「代码随想录」相见恨晚!**
74+
75+
**如果感觉题解对你有帮助,不要吝啬给一个👍吧!**
76+

0 commit comments

Comments
 (0)