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 d0ffa80 commit 41fd9c0Copy full SHA for 41fd9c0
longest-common-subsequence/yhkee0404.dart
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ int longestCommonSubsequence(String text1, String text2) {
3
+ final dp = List.generate(
4
+ text1.length + 1,
5
+ (_) => List.filled(text2.length + 1, 0),
6
+ );
7
+ for (int i = 1; i <= text1.length; i++) {
8
+ for (int j = 1; j <= text2.length; j++) {
9
+ dp[i][j] = text1[i - 1] == text2[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]);
10
+ }
11
12
+ return dp[text1.length][text2.length];
13
14
+}
0 commit comments