Skip to content

Commit

Permalink
Update LongestCommonSubsequence.java
Browse files Browse the repository at this point in the history
for example from the book with words 'fish' and 'fosh' where is a mistake.
  • Loading branch information
Polurival authored and egonSchiele committed Jun 11, 2017
1 parent 468fda7 commit 0a2ed9e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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]);
Expand All @@ -24,7 +24,11 @@ public static void main(String[] args) {
}
} 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;
Expand All @@ -47,4 +51,4 @@ private static void printResult(int[][] arr) {
}
}

}
}

0 comments on commit 0a2ed9e

Please sign in to comment.