Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 98f897d

Browse files
committed
created another solution for problem64
1 parent fa1f2c4 commit 98f897d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

problem64/Solution1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
3+
m, n = len(text2), len(text1)
4+
cache = [[0] * (m +1) for _ in range(n +1)]
5+
6+
for i in range(n-1, -1, -1):
7+
for j in range(m-1, -1, -1):
8+
if text1[i] == text2[j]: cache[i][j] = cache[i+1][j+1] +1
9+
else: cache[i][j] = max(cache[i+1][j], cache[i][j+1])
10+
11+
return cache[0][0]

0 commit comments

Comments
 (0)