zoukankan      html  css  js  c++  java
  • 基于后缀数组的字符串匹配

    计算得到文本串(S)的后缀数组,给出模式串(P),可以通过二分,在(O(|T|log |S|))的时间复杂度内判断模式串是否在文本串中出现过

    bool contain(string text,string pattern){
        int n=text.length();
        int m=pattern.length();
        int l=0,r=n;
        while(r>l){
            int mid=(l+r)>>1;
            if(text.compare(sa[mid],m,pattern)>=0){
                r=mid;
            }
            else l=mid+1;
        }
        return text.compare(sa[r],m,pattern)==0;
    }
    
  • 相关阅读:
    软工人日常
    11.5
    11.4
    11.3
    11.2阅读笔记
    11.1阅读笔记
    10.31 异常
    10.30动手动脑
    10.29
    10.28
  • 原文地址:https://www.cnblogs.com/fxq1304/p/13492352.html
Copyright © 2011-2022 走看看