I am doing an exercise to find the longest common subsequence (LSC) without dynamic programming, so far I have the code that returns the longest common subsequence but I also need to return the length of the sequence, what do I have to do?
this is the code that returns the longest common subsequence
def lcs(str1, str2):
if len(str1) == 0 or len(str2) == 0:
return ""
if str1[-1] == str2[-1]:
return lcs(str1[:-1], str2[:-1]) + str1[-1]
t1 = lcs(str1[:-1], str2)
t2 = lcs(str1, str2[:-1])
if len(t1) > len(t2):
return t1
else:
return t2
How do I return the length of the sequence?