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 99ec887 commit cf0fc60Copy full SHA for cf0fc60
longest-common-subsequence/samthekorean.py
@@ -0,0 +1,13 @@
1
+# m is the length of text1 and n is the length of text2
2
+# TC : O(m * n)
3
+# SC : O(m * n)
4
+class Solution:
5
+ def longestCommonSubsequence(self, text1: str, text2: str) -> int:
6
+ dp = [[0] * (len(text2) + 1) for _ in range(len(text1) + 1)]
7
+ for r in range(1, len(text1) + 1):
8
+ for c in range(1, len(text2) + 1):
9
+ if text1[r - 1] == text2[c - 1]:
10
+ dp[r][c] = 1 + dp[r - 1][c - 1]
11
+ else:
12
+ dp[r][c] = max(dp[r - 1][c], dp[r][c - 1])
13
+ return dp[-1][-1]
0 commit comments