File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 1-
2-
31/**
42 * Given two words word1 and word2, find the minimum number of steps required to
53 * convert word1 to word2. (each operation is counted as 1 step.)
@@ -17,10 +15,10 @@ public int minDistance(String word1, String word2) {
1715 return word1 .length () == 0 ? word2 .length () : word1 .length ();
1816 int [][] arr = new int [word2 .length () + 1 ][word1 .length () + 1 ];
1917 for (int i = 0 ; i <= word1 .length (); i ++) {
20- arr [0 ][i ] = 0 ;
18+ arr [0 ][i ] = i ;
2119 }
2220 for (int j = 0 ; j <= word2 .length (); j ++) {
23- arr [j ][0 ] = 0 ;
21+ arr [j ][0 ] = j ;
2422 }
2523 for (int i = 0 ; i < word1 .length (); i ++) {
2624 for (int j = 0 ; j < word2 .length (); j ++) {
@@ -34,4 +32,8 @@ public int minDistance(String word1, String word2) {
3432 }
3533 return arr [word2 .length ()][word1 .length ()];
3634 }
35+
36+ public static void main (String [] args ) {
37+ System .out .println (new EditDistance ().minDistance ("ab" , "bc" ));
38+ }
3739}
You can’t perform that action at this time.
0 commit comments