Skip to content

Commit 9378440

Browse files
Time: 267 ms (94.93%) | Memory: 19.5 MB (90.53%) - LeetSync
1 parent 553255f commit 9378440

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import math
2+
3+
class Solution:
4+
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
5+
dp = [0] * (len(text2) + 1)
6+
7+
for i in range(1, len(text1) + 1):
8+
dp_j1 = dp[0]
9+
for j in range(1, len(text2) + 1):
10+
dp_j0 = dp[j]
11+
if text1[i - 1] == text2[j - 1]:
12+
dp[j] = dp_j1 + 1
13+
else:
14+
dp[j] = max(dp[j], dp[j - 1])
15+
dp_j1 = dp_j0
16+
17+
return dp[-1]

0 commit comments

Comments
 (0)