Skip to content

Instantly share code, notes, and snippets.

@oshea00
Created May 13, 2020 17:46
Show Gist options
  • Save oshea00/516d143addce63767b29506eebd7444e to your computer and use it in GitHub Desktop.
Save oshea00/516d143addce63767b29506eebd7444e to your computer and use it in GitHub Desktop.
void Main()
{
Console.WriteLine(
LongestMatch("a8dgk1ndflg0s84142kd","093841tgpngh044flg0s84142123rbbdja7")
);
}
string LongestMatch(string small, string large)
{
string currLargest = "";
if (small.Length >= large.Length)
(small, large) = (large, small);
for (int i=0; i < large.Length; i++) {
string tmp = "";
int largePos = i;
for (int j=0; j < small.Length; j++) {
if (largePos > large.Length-1)
continue;
if (small[j]==large[largePos]) {
tmp += small[j];
largePos++;
} else {
if (currLargest.Length < tmp.Length) {
currLargest = tmp;
}
tmp = "";
}
}
}
return currLargest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment