Skip to content

Instantly share code, notes, and snippets.

@bowbowbow
Last active January 18, 2016 05:51
Show Gist options
  • Save bowbowbow/57bd1dc0e268ff7e97d0 to your computer and use it in GitHub Desktop.
Save bowbowbow/57bd1dc0e268ff7e97d0 to your computer and use it in GitHub Desktop.
vector<int> getPi(string p){
int m = (int)p.size(), j=0;
vector<int> pi(m, 0);
for(int i = 1; i< m ; i++){
while(j > 0 && p[i] != p[j])
j = pi[j-1];
if(p[i] == p[j])
pi[i] = ++j;
}
return pi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment