Last active
December 26, 2015 10:09
-
-
Save aaani/7134968 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
int LCPLength(vector<string> input){ | |
//Find the length of shortest string in the input set | |
int minLen = INT32_MAX; | |
for(int i=0;i<input.size();i++){ | |
if(input[i].length()<minLen) minLen=(int)input[i].length(); | |
} | |
bool done = false; | |
int lcpLen=0; | |
for(int j=0;j<minLen;j++){ | |
for(int i=0;i<input.size() && !done;i++){ | |
//Whenever there is a mismatch, set done flag to terminate the function | |
if(input[i][j] != input[0][j]) done=true; | |
} | |
if(done) break; | |
lcpLen++; | |
} | |
return lcpLen; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment