Created
May 13, 2020 17:46
-
-
Save oshea00/516d143addce63767b29506eebd7444e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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