A题用KMP的思想为什么错了?

A题用Kmp的Next数组找为什么错了,求几组反例。
#include <bits/stdc++.h>
using namespace std;
char s[100010];
int nex[100010];
void get_next(const int n){
    int k=-1,j=0;
    nex[0]=-1;
    while(j<n-1){
        if(k==-1||s[j]==s[k]){
            if(s[++j]==s[++k]){
                nex[j]=nex[k];
            }
            else nex[j]=k;
        }
        else k=nex[k];
    }
}
int main(){
    int n;
    scanf("%d %s",&n,s);
    get_next(n);
    for(int i=1;i<n;i++)
        if(s[i]<s[nex[i]]){printf("YES\n");return 0;}
    printf("NO\n");
    return 0;
}

全部评论

相关推荐

一天代码十万三:这都不能算简历吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务