Created
December 6, 2017 15:33
-
-
Save arrieta/ddbc043f068fe402ad3f47660c0edcd9 to your computer and use it in GitHub Desktop.
Longest Common Subsequence
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
def lcs(s1, s2): | |
def lcs_(s1, s2, m, n): | |
if (m < 0) or (n < 0): | |
return 0 | |
elif s1[m] == s2[n]: | |
return 1 + lcs_(s1, s2, m - 1, n - 1) | |
else: | |
return max(lcs_(s1, s2, m - 1, n), | |
lcs_(s1, s2, m, n - 1)) | |
return lcs_(s1, s2, len(s1) - 1, len(s2) - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment