Skip to content

Commit 31693bd

Browse files
refactor 583
1 parent afd6cb2 commit 31693bd

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/main/java/com/fishercoder/solutions/_583.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
*/
1818
public class _583 {
1919

20-
public int minDistance(String word1, String word2) {
21-
int m = word1.length();
22-
int n = word2.length();
23-
int[][] dp = new int[m + 1][n + 1];
24-
for (int i = 1; i <= m; i++) {
25-
for (int j = 1; j <= n; j++) {
26-
dp[i][j] = word1.charAt(i - 1) == word2.charAt(j - 1) ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1]);
20+
public static class Solution1 {
21+
22+
public int minDistance(String word1, String word2) {
23+
int m = word1.length();
24+
int n = word2.length();
25+
int[][] dp = new int[m + 1][n + 1];
26+
for (int i = 1; i <= m; i++) {
27+
for (int j = 1; j <= n; j++) {
28+
dp[i][j] = word1.charAt(i - 1) == word2.charAt(j - 1) ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1]);
29+
}
2730
}
31+
return m + n - 2 * dp[m][n];
2832
}
29-
return m + n - 2 * dp[m][n];
3033
}
3134

3235
}

src/test/java/com/fishercoder/_583Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010
* Created by fishercoder on 5/18/17.
1111
*/
1212
public class _583Test {
13-
private static _583 test;
13+
private static _583.Solution1 solution1;
1414
private static String word1;
1515
private static String word2;
1616

1717
@BeforeClass
1818
public static void setup() {
19-
test = new _583();
19+
solution1 = new _583.Solution1();
2020
}
2121

2222
@Test
2323
public void test1() {
2424
word1 = "sea";
2525
word2 = "eat";
26-
assertEquals(2, test.minDistance(word1, word2));
26+
assertEquals(2, solution1.minDistance(word1, word2));
2727
}
2828

2929
@Test
3030
public void test2() {
3131
word1 = "sea";
3232
word2 = "ate";
33-
assertEquals(4, test.minDistance(word1, word2));
33+
assertEquals(4, solution1.minDistance(word1, word2));
3434
}
3535
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy