You are viewing a single comment's thread. Return to all comments →
What is wrong withthe code:
memo=[[0]*(len(s2)+1) for _ in range((len(s1)+1))] for i in range(1, len(s1)+1): for j in range(1, len(s2)+1): if s1[i-1]==s2[j-1] : memo[i][j]=memo[i-1][j-1]+1 else: memo[i][j]=max(memo[i-1][j], memo[i][j-1]) _cur=memo[-1][-1] suffixes=[[0]*(len(s2)+1) for _ in range((len(s1)+1))] print(memo) for i in range(len(s1)-1, -1, -1): for j in range(len(s2)-1, -1, -1): print(s1[i], s2[j]) if s1[i]==s2[j]: suffixes[i][j]=suffixes[i+1][j+1]+1 else: suffixes[i][j]=max(suffixes[i+1][j], suffixes[i][j+1]) count=0 print(suffixes) for i in range(len(s1)+1): seen=set() for j in range(len(s2)): if memo[i][j]+suffixes[i][j+1]+1>_cur: count+=1 seen.add(s2[j]) return count
Seems like cookies are disabled on this browser, please enable them to open this website
LCS Returns
You are viewing a single comment's thread. Return to all comments →
What is wrong withthe code: