Created
August 25, 2015 16:42
-
-
Save manuchandel/0fd71b79c38e07250cd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void longestPrefixSuffix(string &p,int *A,int n){ | |
A[0]=0; | |
int i=1,j=0; | |
while(i<n){ | |
if(p[i]==p[j]){ // match found | |
A[i]=j+1; | |
i++; | |
j++; | |
}else if(j==0){ | |
A[i]=0; | |
i++; | |
}else j=A[j-1]; // search in the next longest prefix | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment