Advertisement
Kevin_Zhang

Untitled

Oct 27th, 2019
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.23 KB | None | 0 0
  1. vector<int> zfunc(const string &w){
  2.     vector<int> z(w.size());
  3.     for(int l = 0, i = 1;i < w.size();++i){
  4.         z[i] = max(0, min(l+z[l] - i, z[i-l]));
  5.         while(i + z[i] < w.size() and w[i+z[i]] == w[z[i]])++z[i], l = i;
  6.     }
  7.     return z;
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement