File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
09_dynamic_programming/java/01_longest_common_subsequence/src Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class LongestCommonSubsequence {
4
4
public static void main (String [] args ) {
5
- // if (word_a[i] == word_b[1 ]) {
5
+ // if (word_a[i] == word_b[j ]) {
6
6
// cell[i][j] = cell[i - 1][j - 1] + 1;
7
7
// } else {
8
8
// cell[i][j] = Math.Max(cell[i - 1][j], cell[i][j - 1]);
@@ -24,7 +24,11 @@ public static void main(String[] args) {
24
24
}
25
25
} else {
26
26
// The letters don't match.
27
- if (i > 0 && j > 0 ) {
27
+ if (i == 0 && j > 0 ) {
28
+ cell [i ][j ] = cell [i ][j - 1 ];
29
+ } else if (i > 0 && j == 0 ) {
30
+ cell [i ][j ] = cell [i - 1 ][j ];
31
+ } else if (i > 0 && j > 0 ) {
28
32
cell [i ][j ] = Math .max (cell [i - 1 ][j ], cell [i ][j - 1 ]);
29
33
} else {
30
34
cell [i ][j ] = 0 ;
@@ -47,4 +51,4 @@ private static void printResult(int[][] arr) {
47
51
}
48
52
}
49
53
50
- }
54
+ }
You can’t perform that action at this time.
0 commit comments