Skip to content

Commit 06bee5e

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Update 1143. Longest Common Subsequence.py
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com> Co-Authored-By: Shiwangi Srivastava <174641070+IamShiwangi@users.noreply.github.com>
1 parent 4d8fc1d commit 06bee5e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
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(text1), len(text2)
4+
f = [[0] * (n + 1) for _ in range(m + 1)]
5+
for i in range(1, m + 1):
6+
for j in range(1, n + 1):
7+
if text1[i - 1] == text2[j - 1]:
8+
f[i][j] = f[i - 1][j - 1] + 1
9+
else:
10+
f[i][j] = max(f[i - 1][j], f[i][j - 1])
11+
return f[m][n]

0 commit comments

Comments
 (0)