Skip to content

Commit d60cbc7

Browse files
committed
refine
1 parent 44f7df3 commit d60cbc7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

EditDistance.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
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
}

0 commit comments

Comments
 (0)