Skip to content

Commit afb21a7

Browse files
author
He Hao
committed
add another solution for LCS
1 parent 7755edf commit afb21a7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

leetcode_python_solutions/1143.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@ def longestCommonSubsequence(self, text1: str, text2: str) -> int:
99
else:
1010
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
1111
return dp[-1][-1]
12+
13+
14+
# class Solution:
15+
# def longestCommonSubsequence(self, text1: str, text2: str) -> int:
16+
# return self.lcs(text1, text2, len(text1) - 1, len(text2) - 1, {})
17+
#
18+
# def lcs(self, text1, text2, i, j, memo):
19+
# if i < 0 or j < 0:
20+
# return 0
21+
# if (i, j) not in memo:
22+
# if text1[i] == text2[j]:
23+
# memo[(i, j)] = 1 + self.lcs(text1, text2, i - 1, j - 1, memo)
24+
# else:
25+
# memo[(i, j)] = max(self.lcs(text1, text2, i, j - 1, memo), self.lcs(text1, text2, i - 1, j, memo))
26+
#
27+
# return memo[(i, j)]

0 commit comments

Comments
 (0)