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 735bef2

Browse files
Merge pull request #162 from JezaChen/main
Update 03.String-KMP.md
2 parents 8f11154 + 62c7e76 commit 735bef2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎Contents/06.String/02.String-Single-Pattern-Matching/03.String-KMP.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ KMP 算法就是使用了这样的思路,对模式串 $p$ 进行了预处理
5050
- $next[0] = 0,ドル因为 `"A"` 中无有相同前缀后缀,最大长度为 0ドル$。
5151
- $next[1] = 0,ドル因为 `"AB"` 中无相同前缀后缀,最大长度为 0ドル$。
5252
- $next[2] = 0,ドル因为 `"ABC"` 中无相同前缀后缀,最大长度为 0ドル$。
53-
- $next[3] = 1,ドル因为 `"ABCA"` 中有相同的前缀后缀 `"a"`,最大长度为 1ドル$。
53+
- $next[3] = 1,ドル因为 `"ABCA"` 中有相同的前缀后缀 `"A"`,最大长度为 1ドル$。
5454
- $next[4] = 2,ドル因为 `"ABCAB"` 中有相同的前缀后缀 `"AB"`,最大长度为 2ドル$。
5555
- $next[5] = 3,ドル因为 `"ABCABC"` 中有相同的前缀后缀 `"ABC"`,最大长度为 3ドル$。
5656
- $next[6] = 0,ドル因为 `"ABCABCD"` 中无相同前缀后缀,最大长度为 0ドル$。
@@ -68,7 +68,7 @@ KMP 算法就是使用了这样的思路,对模式串 $p$ 进行了预处理
6868
如果文本串 $T[i: i + m]$ 与模式串 $p$ 的失配是在第 $j$ 个下标位置发生的,那么:
6969

7070
- 文本串 $T$ 从下标位置 $i$ 开始连续的 $j$ 个字符,一定与模式串 $p$ 的前 $j$ 个字符一模一样,即:$T[i: i + j] == p[0: j]$。
71-
- 而如果模式串 $p$ 的前 $j$ 个字符中,前 $k$ 位前缀和后 $k$ 位后缀相同,即 $p[0: k] == p[j - k: j],ドル并且要保证 $k$ 要尽可能长。
71+
- 而如果模式串 $p$ 的前 $j$ 个字符中,前 $k$ 位前缀和后 $k$ 位后缀相同,即 $p[0: k] == p[j - k: j],ドル并且要保证 $k$ 要尽可能长。
7272

7373
可以推出:文本串子串的后 $k$ 位后缀和模式串子串的前 $k$ 位是相同的,即 $T[i + j - k: i + j] == p[0: k]$(这部分是已经比较过的),不需要再比较了,可以直接跳过。
7474

@@ -151,4 +151,4 @@ print(kmp("ababbbbaaabbbaaa", "bbbb"))
151151
- 【博文】[从头到尾彻底理解 KMP - 结构之法 算法之道 - CSDN博客](https://blog.csdn.net/v_JULY_v/article/details/7041827?spm=1001.2014.3001.5502)
152152
- 【博文】[字符串匹配的 KMP 算法 - 阮一峰的网络日志](http://www.ruanyifeng.com/blog/2013/05/Knuth–Morris–Pratt_algorithm.html)
153153
- 【题解】[多图预警 - 详解 KMP 算法 - 实现 strStr() - 力扣](https://leetcode.cn/problems/implement-strstr/solution/duo-tu-yu-jing-xiang-jie-kmp-suan-fa-by-w3c9c/)
154-
- 【题解】[「代码随想录」KMP算法详解 - 实现 strStr() - 力扣](https://leetcode.cn/problems/implement-strstr/solution/dai-ma-sui-xiang-lu-kmpsuan-fa-xiang-jie-mfbs/)
154+
- 【题解】[「代码随想录」KMP算法详解 - 实现 strStr() - 力扣](https://leetcode.cn/problems/implement-strstr/solution/dai-ma-sui-xiang-lu-kmpsuan-fa-xiang-jie-mfbs/)

0 commit comments

Comments
(0)

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