Update LongestCommonSubsequence.java
for example from the book with words 'fish' and 'fosh' where is a mistake.
This commit is contained in:
committed by
Aditya Bhargava
parent
468fda77a2
commit
0a2ed9e4bb
@@ -2,7 +2,7 @@ import java.util.Arrays;
|
||||
|
||||
public class LongestCommonSubsequence {
|
||||
public static void main(String[] args) {
|
||||
// if (word_a[i] == word_b[1]) {
|
||||
// if (word_a[i] == word_b[j]) {
|
||||
// cell[i][j] = cell[i - 1][j - 1] + 1;
|
||||
// } else {
|
||||
// cell[i][j] = Math.Max(cell[i - 1][j], cell[i][j - 1]);
|
||||
@@ -24,7 +24,11 @@ public class LongestCommonSubsequence {
|
||||
}
|
||||
} else {
|
||||
// The letters don't match.
|
||||
if (i > 0 && j > 0) {
|
||||
if (i == 0 && j > 0) {
|
||||
cell[i][j] = cell[i][j - 1];
|
||||
} else if (i > 0 && j == 0) {
|
||||
cell[i][j] = cell[i - 1][j];
|
||||
} else if (i > 0 && j > 0) {
|
||||
cell[i][j] = Math.max(cell[i - 1][j], cell[i][j - 1]);
|
||||
} else {
|
||||
cell[i][j] = 0;
|
||||
@@ -47,4 +51,4 @@ public class LongestCommonSubsequence {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user