We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d750252 commit 1937d70Copy full SHA for 1937d70
1 file changed
longest-common-subsequence/HYUNAHKO.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def longestCommonSubsequence(self, text1: str, text2: str) -> int:
3
+ # Dynamic programming
4
+ n = len(text1)
5
+ m = len(text2)
6
+
7
+ # text1 - col, text2 - row
8
+ dp= [[0] * (n+1) for _ in range(m+1)]
9
10
+ for i in range(1, m+1):
11
+ for j in range(1, n+1):
12
+ if text2[i-1] == text1[j-1]:
13
+ dp[i][j] = dp[i-1][j-1] + 1
14
+ else:
15
+ dp[i][j] = max(dp[i-1][j], dp[i][j-1])
16
17
+ return dp[m][n]
0 commit comments