anoosykh95

Untitled

Jul 22nd, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. int lps[1<<17];
  2. string s;
  3. void calclps()
  4. {
  5.     lps[0]=-1;
  6.     int len=s.size();
  7.     for(int i=1;i<len;++i)
  8.     {
  9.         int j=lps[i-1];
  10.         lps[i]=-1;
  11.         while(1)
  12.         {
  13.             if(s[i]==s[j+1]){lps[i]=j+1;break;}
  14.             if(j==-1)break;
  15.             j=lps[j];
  16.         }
  17.     }
  18. }
Add Comment
Please, Sign In to add comment