diff --git a/README.md b/README.md index 45530e70..bfff09da 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ ![算法面试知识大纲](https://img-blog.csdnimg.cn/20200729181420491.png) +# 算法视频讲解 + +* [KMP算法(理论篇)B站视频](https://www.bilibili.com/video/BV1PD4y1o7nd) +* [KMP算法(代码篇)B站视频](https://www.bilibili.com/video/BV1M5411j7Xx) +* [回溯算法(理论篇)B站视频](https://www.bilibili.com/video/BV1cy4y167mM) + # 算法文章精选 **提示:在电脑端看如下文章的,看不到文章的评论区,建议在手机端「代码随想录」公众号里也翻一下对应的文章,评论区有录友们的打卡总结,相信会和你有不少共鸣!** @@ -150,6 +156,8 @@ * [本周小结!(回溯算法系列三)](https://mp.weixin.qq.com/s/tLkt9PSo42X60w8i94ViiA) * [本周小结!(回溯算法系列三)续集](https://mp.weixin.qq.com/s/kSMGHc_YpsqL2j-jb_E_Ag) * [视频来了!!带你学透回溯算法(理论篇)](https://mp.weixin.qq.com/s/wDd5azGIYWjbU0fdua_qBg) + * [回溯算法:重新安排行程](https://mp.weixin.qq.com/s/3kmbS4qDsa6bkyxR92XCTA) + * [回溯算法:N皇后问题](https://mp.weixin.qq.com/s/lU_QwCMj6g60nh8m98GAWg) (持续更新中....) @@ -356,6 +364,7 @@ |[0127.单词接龙](https://github.com/youngyangyang04/leetcode/blob/master/problems/0127.单词接龙.md) |广度优先搜索 |中等|**广度优先搜索**| |[0129.求根到叶子节点数字之和](https://github.com/youngyangyang04/leetcode/blob/master/problems/0129.求根到叶子节点数字之和.md) |二叉树 |中等|**递归/回溯** 递归里隐藏着回溯,和113.路径总和II类似| |[0131.分割回文串](https://github.com/youngyangyang04/leetcode/blob/master/problems/0131.分割回文串.md) |回溯 |中等|**回溯**| +|[0135.分发糖果](https://github.com/youngyangyang04/leetcode/blob/master/problems/0135.分发糖果.md) |贪心 |困难|**贪心**好题目| |[0141.环形链表](https://github.com/youngyangyang04/leetcode/blob/master/problems/0141.环形链表.md) |链表 |简单|**快慢指针/双指针**| |[0142.环形链表II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0142.环形链表II.md) |链表 |中等|**快慢指针/双指针**| |[0143.重排链表](https://github.com/youngyangyang04/leetcode/blob/master/problems/0143.重排链表.md) |链表 |中等|**快慢指针/双指针** 也可以用数组,双向队列模拟,考察链表综合操作的好题| diff --git a/pics/51.N皇后.png b/pics/51.N皇后.png index 14fbd8ed..dcc9f490 100644 Binary files a/pics/51.N皇后.png and b/pics/51.N皇后.png differ diff --git a/problems/0051.N皇后.md b/problems/0051.N皇后.md index 275103a2..dee9f164 100644 --- a/problems/0051.N皇后.md +++ b/problems/0051.N皇后.md @@ -89,7 +89,7 @@ void backtracking(int n, int row, vector& chessboard) { * 递归终止条件 在如下树形结构中: -![51.N皇后](https://img-blog.csdnimg.cn/20201116173551789.png) +![51.N皇后](https://img-blog.csdnimg.cn/20201117165155239.png) 可以看出,当递归到棋盘最底层(也就是叶子节点)的时候,就可以收集结果并返回了。 diff --git a/problems/0052.N皇后II.md b/problems/0052.N皇后II.md index 4fd6482d..035ac5c1 100644 --- a/problems/0052.N皇后II.md +++ b/problems/0052.N皇后II.md @@ -36,7 +36,8 @@ n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并 class Solution { private: int count = 0; -void backtracking(int n, int row, vector& chessboard, vector>& result) { +vector> result; +void backtracking(int n, int row, vector& chessboard) { if (row == n) { count++; return; @@ -44,7 +45,7 @@ void backtracking(int n, int row, vector& chessboard, vector& chessboard, int n) { public: int totalNQueens(int n) { + result.clear(); std::vector chessboard(n, std::string(n, '.')); vector> result; - backtracking(n, 0, chessboard, result); + backtracking(n, 0, chessboard); return count; } diff --git a/problems/0135.分发糖果.md b/problems/0135.分发糖果.md index 66fa0131..62336ced 100644 --- a/problems/0135.分发糖果.md +++ b/problems/0135.分发糖果.md @@ -11,7 +11,7 @@ 代码如下: -``` +```C++ // 从前向后 for (int i = 1; i < ratings.size(); i++) { if (ratings[i] > ratings[i - 1]) candyVec[i] = candyVec[i - 1] + 1; @@ -37,7 +37,7 @@ for (int i = 1; i < ratings.size(); i++) { 所以代码如下: -``` +```C++ // 从后向前 for (int i = ratings.size() - 2; i >= 0; i--) { if (ratings[i] > ratings[i + 1] ) { @@ -46,21 +46,8 @@ for (int i = ratings.size() - 2; i >= 0; i--) { } ``` -* 将问题分解为若干个子问题 -* 找出适合的贪心策略 -* 求解每一个子问题的最优解 -* 将局部最优解堆叠成全局最优解 - -* 分解为子问题 - - - -这道题目上来也是没什么思路啊 - - -这道题目不好想啊,贪心很巧妙 - -``` +整体代码如下: +```C++ class Solution { public: int candy(vector& ratings) { @@ -81,5 +68,9 @@ public: return result; } }; - ``` + +> **我是[程序员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),关注后就会发现和「代码随想录」相见恨晚!** + +**如果感觉题解对你有帮助,不要吝啬给一个👍吧!** +