Longest Non-Overlapping Repeated Substring using Suffix Tree/Array (Algorithm Only)

后端 未结 8 2056
遇见更好的自我
遇见更好的自我 2021-02-13 16:30

I need to find the longest non-overlapping repeated substring in a String. I have the suffix tree and suffix array of the string available.

When overlapping is allowed,

8条回答
  •  离开以前
    2021-02-13 17:27

    Complete code:

    #include 
    using namespace std;
    int cplen(string a,string b){
        int i,to=min(a.length(),b.length());
        int ret=0;
        for(i=0;i>str;
            len=str.length();
            vector >vv;
            maphatbc;
            string pp="";
            for(i=len-1;i>=0;i--){
                hatbc[str[i]]++;
                pp=str.substr(i,len-i);
                vv.push_back(make_pair(pp,i));
                }
            if(len==1 || (int)hatbc.size()==len){
                printf("0\n");
                continue;
                }
            if(hatbc.size()==1){
                printf("%d\n",len/2);
                continue;
                }
            char prev=str[0];
            int foo=1,koo=0;
            for(i=1;i=cpl)
                    ans=max(ans,cpl);
                }
            printf("%d\n",ans);
            }
        return 0;
        }
    

    Complexity : O(n*log(n)) (due to sorting)

提交回复
热议问题