Skip to content

Commit b4a38fb

Browse files
committed
大更新:开头添加对应的力扣题目
1 parent 74a3d06 commit b4a38fb

File tree

78 files changed

+2431
-2283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2431
-2283
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ English version repo and Gitbook is on [english branch](https://github.com/labul
3737

3838
Gitbook 地址:https://labuladong.gitbook.io/algo/
3939

40-
2、建议关注我的公众号 **labuladong**,坚持高质量原创,说是最良心最硬核的技术公众号都不为过。本仓库的文章就是从公众号里整理出来的**一部分**内容,公众号后台回复关键词【电子书】可以获得这份小抄的完整版本;回复【加群】可以加入我们的刷题群,和大家一起讨论算法问题,分享内推机会:
40+
3、建议关注我的公众号 **labuladong**,坚持高质量原创,说是最良心最硬核的技术公众号都不为过。本仓库的文章就是从公众号里整理出来的**一部分**内容,公众号后台回复关键词【电子书】可以获得这份小抄的完整版本;回复【加群】可以加入我们的刷题群,和大家一起讨论算法问题,分享内推机会:
4141

4242
<p align='center'>
4343
<img src="https://gitee.com/labuladong/pictures/raw/master/qrcode.jpg" width = "200" />

pictures/LRU算法/put.jpg

38.4 KB
Loading

pictures/souyisou.png

20.1 KB
Loading

pictures/table_qr2.jpg

187 KB
Loading

pictures/正则/1.jpeg

114 KB
Loading

pictures/正则/2.jpeg

115 KB
Loading

pictures/正则/3.jpeg

115 KB
Loading

pictures/正则/4.jpeg

111 KB
Loading

动态规划系列/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
这就是思维模式的框架,**本章都会按照以上的模式来解决问题,辅助读者养成这种模式思维**,有了方向遇到问题就不会抓瞎,足以解决一般的动态规划问题。
1010

11-
欢迎关注我的公众号 labuladong,方便获得最新的优质文章
11+
欢迎关注我的公众号 labuladong,查看全部文章
1212

1313
![labuladong二维码](../pictures/qrcode.jpg)

动态规划系列/动态规划之KMP字符匹配算法.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# 动态规划之KMP字符匹配算法
22

3+
4+
<p align='center'>
5+
<a href="https://github.com/labuladong/fucking-algorithm" target="view_window"><img alt="GitHub" src="https://img.shields.io/github/stars/labuladong/fucking-algorithm?label=Stars&style=flat-square&logo=GitHub"></a>
6+
<a href="https://www.zhihu.com/people/labuladong"><img src="https://img.shields.io/badge/%E7%9F%A5%E4%B9%8E-@labuladong-000000.svg?style=flat-square&logo=Zhihu"></a>
7+
<a href="https://i.loli.net/2020/10/10/MhRTyUKfXZOlQYN.jpg"><img src="https://img.shields.io/badge/公众号-@labuladong-000000.svg?style=flat-square&logo=WeChat"></a>
8+
<a href="https://space.bilibili.com/14089380"><img src="https://img.shields.io/badge/B站-@labuladong-000000.svg?style=flat-square&logo=Bilibili"></a>
9+
</p>
10+
11+
![](../pictures/souyisou.png)
12+
13+
相关推荐:
14+
* [经典动态规划:最长公共子序列](https://labuladong.gitbook.io/algo)
15+
* [特殊数据结构:单调栈](https://labuladong.gitbook.io/algo)
16+
17+
读完本文,你不仅学会了算法套路,还可以顺便去 LeetCode 上拿下如下题目:
18+
19+
[28.实现 strStr()](https://leetcode-cn.com/problems/implement-strstr)
20+
21+
**-----------**
22+
323
KMP 算法(Knuth-Morris-Pratt 算法)是一个著名的字符串匹配算法,效率很高,但是确实有点复杂。
424

525
很多读者抱怨 KMP 算法无法理解,这很正常,想到大学教材上关于 KMP 算法的讲解,也不知道有多少未来的 Knuth、Morris、Pratt 被提前劝退了。有一些优秀的同学通过手推 KMP 算法的过程来辅助理解该算法,这是一种办法,不过本文要从逻辑层面帮助读者理解算法的原理。十行代码之间,KMP 灰飞烟灭。
@@ -37,7 +57,7 @@ int search(String pat, String txt) {
3757
}
3858
```
3959

40-
对于暴力算法,如果出现不匹配字符,同时回退 `txt``pat` 的指针,嵌套 for 循环,时间复杂度 $O(MN)$,空间复杂度$O(1)$。最主要的问题是,如果字符串中重复的字符比较多,该算法就显得很蠢。
60+
对于暴力算法,如果出现不匹配字符,同时回退 `txt``pat` 的指针,嵌套 for 循环,时间复杂度 `O(MN)`,空间复杂度`O(1)`。最主要的问题是,如果字符串中重复的字符比较多,该算法就显得很蠢。
4161

4262
比如 txt = "aaacaaab" pat = "aaab":
4363

@@ -399,12 +419,14 @@ public class KMP {
399419

400420
KMP 算法也就是动态规划那点事,我们的公众号文章目录有一系列专门讲动态规划的,而且都是按照一套框架来的,无非就是描述问题逻辑,明确 `dp` 数组含义,定义 base case 这点破事。希望这篇文章能让大家对动态规划有更深的理解。
401421

402-
**致力于把算法讲清楚!欢迎关注我的微信公众号 labuladong,查看更多通俗易懂的文章**
403422

404-
![labuladong](../pictures/labuladong.png)
405423

406-
[上一篇:贪心算法之区间调度问题](../动态规划系列/贪心算法之区间调度问题.md)
424+
**_____________**
425+
426+
**刷算法,学套路,认准 labuladong,公众号和 [在线电子书](https://labuladong.gitbook.io/algo) 持续更新最新文章**
407427

408-
[下一篇:团灭 LeetCode 股票买卖问题](../动态规划系列/团灭股票问题.md)
428+
**本小抄即将出版,微信扫码关注公众号,后台回复「小抄」限时免费获取,回复「进群」可进刷题群一起刷题,带你搞定 LeetCode**
409429

410-
[目录](../README.md#目录)
430+
<p align='center'>
431+
<img src="../pictures/table_qr2.jpg" width=500 >
432+
</p>

0 commit comments

Comments
 (0)