文章

3

粉丝

87

获赞

3

访问

93

头像
删除字符串2 题解:考虑是否出现新组合,KMP
P1027 贵州大学2019机试
发布于2025年3月10日 13:07
阅读数 52

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

void getNext(const string& pattern, vector<int>& next) {
    int len = pattern.length();
    int k = -1, j = 0;
    next[0] = -1;

    while (j < len - 1) {
        if (k == -1 || pattern[k] == pattern[j]) {
            k++;
            j++;
            next[j] = k;
        } else {
            k = next[k];
        }
    }
}

int KMP(const string& s, const string& p) {
    int m = s.length();
   ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发