Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
youngyangyang04 committed Nov 24, 2020
1 parent b9e475c commit e08fd0e
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 42 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

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

# 算法视频讲解
# B站算法视频讲解

* [KMP算法(理论篇)B站视频](https://www.bilibili.com/video/BV1PD4y1o7nd)
* [KMP算法(代码篇)B站视频](https://www.bilibili.com/video/BV1M5411j7Xx)
* [回溯算法(理论篇)B站视频](https://www.bilibili.com/video/BV1cy4y167mM)
* [KMP算法(理论篇)](https://www.bilibili.com/video/BV1PD4y1o7nd)
* [KMP算法(代码篇)](https://www.bilibili.com/video/BV1M5411j7Xx)
* [回溯算法(理论篇)](https://www.bilibili.com/video/BV1cy4y167mM)
* [回溯算法之组合问题(力扣题目:77.组合)](https://www.bilibili.com/video/BV1ti4y1L7cv)

(持续更新中....)

Expand Down Expand Up @@ -417,6 +418,7 @@
|[0434.字符串中的单词数](https://github.com/youngyangyang04/leetcode/blob/master/problems/0434.字符串中的单词数.md) |字符串 |简单|**模拟**|
|[0435.无重叠区间](https://github.com/youngyangyang04/leetcode/blob/master/problems/0435.无重叠区间.md) |贪心 |中等|**贪心** 经典题目,有点难|
|[0450.删除二叉搜索树中的节点](https://github.com/youngyangyang04/leetcode/blob/master/problems/0450.删除二叉搜索树中的节点.md) ||中等|**递归**|
|[0452.用最少数量的箭引爆气球](https://github.com/youngyangyang04/leetcode/blob/master/problems/0452.用最少数量的箭引爆气球.md) |贪心/排序 |中等|**贪心** 经典题目|
|[0454.四数相加II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0454.四数相加II.md) |哈希表 |中等| **哈希**|
|[0455.分发饼干](https://github.com/youngyangyang04/leetcode/blob/master/problems/0455.分发饼干.md) |贪心 |简单| **贪心**|
|[0459.重复的子字符串](https://github.com/youngyangyang04/leetcode/blob/master/problems/0459.重复的子字符串.md) |字符创 |简单| **KMP**|
Expand Down Expand Up @@ -454,6 +456,7 @@
|[0977.有序数组的平方](https://github.com/youngyangyang04/leetcode/blob/master/problems/0977.有序数组的平方.md) |数组 |中等|**双指针** 还是比较巧妙的|
|[1002.查找常用字符](https://github.com/youngyangyang04/leetcode/blob/master/problems/1002.查找常用字符.md) ||简单|****|
|[1047.删除字符串中的所有相邻重复项](https://github.com/youngyangyang04/leetcode/blob/master/problems/1047.删除字符串中的所有相邻重复项.md) |哈希表 |简单|**哈希表/数组**|
|[1049.最后一块石头的重量II](https://github.com/youngyangyang04/leetcode/blob/master/problems/1049.最后一块石头的重量II.md) |动态规划 |中等|**01背包**|
|[1207.独一无二的出现次数](https://github.com/youngyangyang04/leetcode/blob/master/problems/1207.独一无二的出现次数.md) |哈希表 |简单|**哈希** 两层哈希|
|[1356.根据数字二进制下1的数目排序](https://github.com/youngyangyang04/leetcode/blob/master/problems/1356.根据数字二进制下1的数目排序.md) |位运算 |简单|**位运算** 巧妙的计算二进制中1的数量|
|[1365.有多少小于当前数字的数字](https://github.com/youngyangyang04/leetcode/blob/master/problems/1365.有多少小于当前数字的数字.md) |数组、哈希表 |简单|**哈希** 从后遍历的技巧很不错|
Expand Down
Binary file added pics/452.用最少数量的箭引爆气球.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pics/455.分发饼干.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed pics/93_复原IP地址.png
Binary file not shown.
10 changes: 5 additions & 5 deletions problems/0017.电话号码的字母组合.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

## 题目地址
https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/

> 多个集合求组合问题。
# 17.电话号码的字母组合
Expand Down Expand Up @@ -60,7 +57,7 @@ const string letterMap[10] = {

例如:输入:"23",抽象为树形结构,如图所示:

<img src='../pics/17. 电话号码的字母组合.png' width=600> </img></div>
![17. 电话号码的字母组合](https://img-blog.csdnimg.cn/20201123200304469.png)

图中可以看出遍历的深度,就是输入"23"的长度,而叶子节点就是我们要收集的结果,输出["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]

Expand Down Expand Up @@ -232,4 +229,7 @@ public:

**就酱,如果学到了,就帮Carl转发一波吧,让更多小伙伴知道这里!**

> 更多算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

2 changes: 2 additions & 0 deletions problems/0027.移除元素.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ public:
};
```

拓展: 也可以一个指向前面,一个指向后面,遇到需要删除的就交换,最后返回指针的位置加1,只不过这么做更改了数组元素的位置了,不算是移除元素。

> 更多算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
12 changes: 8 additions & 4 deletions problems/0039.组合总和.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ candidates 中的数字可以无限制重复被选取。

本题搜索的过程抽象成树形结构如下:

<img src='../pics/39.组合总和.png' width=600> </img></div>
![39.组合总和](https://img-blog.csdnimg.cn/20201123202227835.png)

注意图中叶子节点的返回条件,因为本题没有组合数量要求,仅仅是总和的限制,所以递归没有层数的限制,只要选取的元素总和超过target,就返回!

Expand Down Expand Up @@ -75,7 +75,7 @@ void backtracking(vector<int>& candidates, int target, int sum, int startIndex)

在如下树形结构中:

<img src='../pics/39.组合总和.png' width=600> </img></div>
![39.组合总和](https://img-blog.csdnimg.cn/20201123202227835.png)

从叶子节点可以清晰看到,终止只有两种情况,sum大于target和sum等于target。

Expand Down Expand Up @@ -148,7 +148,7 @@ public:

在这个树形结构中:

<img src='../pics/39.组合总和.png' width=600> </img></div>
![39.组合总和](https://img-blog.csdnimg.cn/20201123202227835.png)

以及上面的版本一的代码大家可以看到,对于sum已经大于target的情况,其实是依然进入了下一层递归,只是下一层递归结束判断的时候,会判断sum > target的话就返回。

Expand All @@ -160,7 +160,7 @@ public:

如图:

<img src='../pics/39.组合总和1.png' width=600> </img></div>
![39.组合总和1](https://img-blog.csdnimg.cn/20201123202349897.png)


for循环剪枝代码如下:
Expand Down Expand Up @@ -222,3 +222,7 @@ public:

**就酱,如果感觉很给力,就帮Carl宣传一波吧,哈哈**

> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

8 changes: 5 additions & 3 deletions problems/0040.组合总和II.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
> 这篇可以说是全网把组合问题如何去重,讲的最清晰的了!

# 40.组合总和II

题目链接:https://leetcode-cn.com/problems/combination-sum-ii/
Expand Down Expand Up @@ -65,7 +64,7 @@ candidates 中的每个数字在每个组合中只能使用一次。

选择过程树形结构如图所示:

<img src='../pics/40.组合总和II.png' width=600> </img></div>
![40.组合总和II](https://img-blog.csdnimg.cn/20201123202736384.png)

可以看到图中,每个节点相对于 [39.组合总和](https://mp.weixin.qq.com/s/FLg8G6EjVcxBjwCbzpACPw)我多加了used数组,这个used数组下面会重点介绍。

Expand Down Expand Up @@ -115,7 +114,7 @@ if (sum == target) {

这块比较抽象,如图:

<img src='../pics/40.组合总和II1.png' width=600> </img></div>
![40.组合总和II1](https://img-blog.csdnimg.cn/20201123202817973.png)

我在图中将used的变化用橘黄色标注上,可以看出在candidates[i] == candidates[i - 1]相同的情况下:

Expand Down Expand Up @@ -201,4 +200,7 @@ public:

**就酱,如果感觉「代码随想录」诚意满满,就帮Carl宣传一波吧,感谢啦!**

> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

13 changes: 9 additions & 4 deletions problems/0077.组合.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ for (int i = 1; i <= n; i++) {

那么我把组合问题抽象为如下树形结构:

<img src='../pics/77.组合.png' width=600> </img></div>
![77.组合](https://img-blog.csdnimg.cn/20201123195223940.png)

可以看出这个棵树,一开始集合是 1,2,3,4, 从左向右取数,取过的数,不在重复取。

Expand Down Expand Up @@ -119,7 +119,7 @@ vector<int> path; // 用来存放符合条件结果

从下图中红线部分可以看出,在集合[1,2,3,4]取1之后,下一层递归,就要在[2,3,4]中取数了,那么下一层递归如何知道从[2,3,4]中取数呢,靠的就是startIndex。

<img src='../pics/77.组合2.png' width=600> </img></div>
![77.组合2](https://img-blog.csdnimg.cn/20201123195328976.png)

所以需要startIndex来记录下一层递归,搜索的起始位置。

Expand All @@ -139,7 +139,7 @@ path这个数组的大小如果达到k,说明我们找到了一个子集大小

如图红色部分:

<img src='../pics/77.组合3.png' width=600> </img></div>
![77.组合3](https://img-blog.csdnimg.cn/20201123195407907.png)

此时用result二维数组,把path保存起来,并终止本层递归。

Expand All @@ -156,7 +156,7 @@ if (path.size() == k) {

回溯法的搜索过程就是一个树型结构的遍历过程,在如下图中,可以看出for循环用来横向遍历,递归的过程是纵向遍历。

<img src='../pics/77.组合1.png' width=600> </img></div>
![77.组合1](https://img-blog.csdnimg.cn/20201123195242899.png)

如此我们才遍历完图中的这棵树。

Expand Down Expand Up @@ -241,3 +241,8 @@ void backtracking(参数) {


**[本题剪枝操作文章链接](https://mp.weixin.qq.com/s/Ri7spcJMUmph4c6XjPWXQA)**

> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

8 changes: 6 additions & 2 deletions problems/0078.子集.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

以示例中nums = [1,2,3]为例把求子集抽象为树型结构,如下:

<img src='../pics/78.子集.png' width=600> </img></div>
![78.子集](https://img-blog.csdnimg.cn/202011232041348.png)

从图中红线部分,可以看出**遍历这个树的时候,把所有节点都记录下来,就是要求的子集集合**

Expand All @@ -62,7 +62,7 @@ void backtracking(vector<int>& nums, int startIndex) {

从图中可以看出:

<img src='../pics/78.子集.png' width=600> </img></div>
![78.子集](https://img-blog.csdnimg.cn/202011232041348.png)

剩余集合为空的时候,就是叶子节点。

Expand Down Expand Up @@ -169,3 +169,7 @@ public:
**就酱,如果感觉收获满满,就帮Carl宣传一波「代码随想录」吧!**


> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

9 changes: 4 additions & 5 deletions problems/0093.复原IP地址.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## 题目地址

> 一些录友表示跟不上现在的节奏,想从头开始打卡学习起来,可以在公众号左下方,「算法汇总」可以找到历史文章,都是按系列排好顺序的,挨个看就可以了,看文章下的留言你就会发现,有很多录友都在从头打卡,你并不孤单!
# 93.复原IP地址
Expand Down Expand Up @@ -47,7 +45,7 @@ s 仅由数字组成

切割问题可以抽象为树型结构,如图:

<img src='../pics/93.复原IP地址.png' width=600> </img></div>
![93.复原IP地址](https://img-blog.csdnimg.cn/20201123203735933.png)


## 回溯三部曲
Expand Down Expand Up @@ -98,7 +96,7 @@ if (pointNum == 3) { // 逗点数量为3时,分隔结束

如果不合法就结束本层循环,如图中剪掉的分支:

<img src='../pics/93.复原IP地址.png' width=600> </img></div>
![93.复原IP地址](https://img-blog.csdnimg.cn/20201123203735933.png)

然后就是递归和回溯的过程:

Expand Down Expand Up @@ -249,6 +247,7 @@ public:
**很多录友都在从头开始打卡学习,看看前面文章的留言区就知道了,你并不孤单!**


> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
> 我是[程序员Carl](https://github.com/youngyangyang04),更多[精彩算法文章](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),期待你的关注!
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

8 changes: 5 additions & 3 deletions problems/0131.分割回文串.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

所以切割问题,也可以抽象为一颗树形结构,如图:

<img src='../pics/131.分割回文串.png' width=600> </img></div>
![131.分割回文串](https://img-blog.csdnimg.cn/20201123203228309.png)

递归用来纵向遍历,for循环用来横向遍历,切割线(就是图中的红线)切割到字符串的结尾位置,说明找到了一个切割方法。

Expand All @@ -68,7 +68,7 @@ void backtracking (const string& s, int startIndex) {

* 递归函数终止条件

<img src='../pics/131.分割回文串.png' width=600> </img></div>
![131.分割回文串](https://img-blog.csdnimg.cn/20201123203228309.png)

从树形结构的图中可以看出:切割线切到了字符串最后面,说明找到了一种切割方法,此时就是本层递归的终止终止条件。

Expand Down Expand Up @@ -234,5 +234,7 @@ public:

**就酱,如果感觉「代码随想录」不错,就把Carl宣传一波吧!**

> 我是[程序员Carl](https://github.com/youngyangyang04),组队刷题可以找我,本文[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),期待你的关注!
> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

13 changes: 8 additions & 5 deletions problems/0216.组合总和III.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## 链接
https://leetcode-cn.com/problems/combination-sum-iii/

> 别看本篇选的是组合总和III,而不是组合总和,本题和上一篇[回溯算法:求组合问题!](https://mp.weixin.qq.com/s/OnBjbLzuipWz_u4QfmgcqQ)相比难度刚刚好!
Expand Down Expand Up @@ -36,7 +34,7 @@ https://leetcode-cn.com/problems/combination-sum-iii/

选取过程如图:

<img src='../pics/216.组合总和III.png' width=600> </img></div>
![216.组合总和III](https://img-blog.csdnimg.cn/20201123195717975.png)

图中,可以看出,只有最后取到集合(1,3)和为4 符合条件。

Expand Down Expand Up @@ -98,7 +96,7 @@ if (path.size() == k) {
本题和[回溯算法:求组合问题!](https://mp.weixin.qq.com/s/OnBjbLzuipWz_u4QfmgcqQ)区别之一就是集合固定的就是9个数[1,...,9],所以for循环固定i<=9

如图:
<img src='../pics/216.组合总和III.png' width=600> </img></div>
![216.组合总和III](https://img-blog.csdnimg.cn/20201123195717975.png)

处理过程就是 path收集每次选取的元素,相当于树型结构里的边,sum来统计path里元素的总和。

Expand Down Expand Up @@ -156,7 +154,7 @@ public:
这道题目,剪枝操作其实是很容易想到了,想必大家看上面的树形图的时候已经想到了。

如图:
<img src='../pics/216.组合总和III1.png' width=600> </img></div>
![216.组合总和III1](https://img-blog.csdnimg.cn/2020112319580476.png)

已选元素总和如果已经大于n(图中数值为4)了,那么往后遍历就没有意义了,直接剪掉。

Expand Down Expand Up @@ -213,3 +211,8 @@ public:
相信做完本题,大家对组合问题应该有初步了解了。

**就酱,如果感觉对你有帮助,就帮Carl转发一下吧,让更多小伙伴知道这里!**

> **我是[程序员Carl](https://github.com/youngyangyang04),可以找我[组队刷题](https://img-blog.csdnimg.cn/20201115103410182.png),也可以在[B站上找到我](https://space.bilibili.com/525438321),本文[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),关注后就会发现和「代码随想录」相见恨晚!**
**如果感觉对你有帮助,不要吝啬给一个👍吧!**

Loading

0 comments on commit e08fd0e

Please sign in to comment.