row1 = [Falsefor col inrange(len2 + 1)] row1[0] = True for i inrange(1, len2 + 1): row1[i] = ( row1[i - 1] and (s2[i - 1] == s3[i - 1]))
row2 = [Falsefor col inrange(len2 + 1)]
for m inrange(1, len1 + 1): row2[0] = (row1[0] and (s1[m - 1] == s3[m - 1])) for n inrange(1, len2 + 1): k = m + n - 1 # why and ? because [m, n] maybe come from up or left, one of the two is the right source. row2[n] = (s1[m - 1] == s3[k] and row1[n]) or (s2[n - 1] == s3[k] and row2[n - 1]) row1, row2 = row2, row1