You are viewing a single comment's thread. Return to all comments →
Variation of LCS by using two alternating rows instead of a full list and by replacing max with if else to avoid time-out errors.
max
if else
def commonChild(s1, s2): m, n = len(s1), len(s2) prev, cur = [0]*(n+1), [0]*(n+1) for i in range(1, m+1): for j in range(1, n+1): if s1[i-1] == s2[j-1]: cur[j] = 1 + prev[j-1] else: if cur[j-1] > prev[j]: cur[j] = cur[j-1] else: cur[j] = prev[j] cur, prev = prev, cur return prev[n]
Seems like cookies are disabled on this browser, please enable them to open this website
Common Child
You are viewing a single comment's thread. Return to all comments →
Variation of LCS by using two alternating rows instead of a full list and by replacing
max
withif else
to avoid time-out errors.