文章目录
前言
在学习kmp算法之前 我们需要知道 kmp 算法是用来干什么用的
KMP算法是一种字符串匹配算法,可以在
O(n+m)
的时间复杂度内实现两个字符串的匹配
。
所谓字符串匹配,是这样一种问题:“字符串 P 是否为字符串 S 的子串?如果是,它出现在 S 的哪些位置?” 其中 S 称为主串;P称为模式串。
#include<iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 +10;
int ne[N];
char p[N],s[N];
int n,m;
void Get_ne()
{
for(int i = 2 , j = 0