File tree Expand file tree Collapse file tree 2 files changed +15
-12
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 17
17
*/
18
18
public class _583 {
19
19
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
+ }
27
30
}
31
+ return m + n - 2 * dp [m ][n ];
28
32
}
29
- return m + n - 2 * dp [m ][n ];
30
33
}
31
34
32
35
}
Original file line number Diff line number Diff line change 10
10
* Created by fishercoder on 5/18/17.
11
11
*/
12
12
public class _583Test {
13
- private static _583 test ;
13
+ private static _583 . Solution1 solution1 ;
14
14
private static String word1 ;
15
15
private static String word2 ;
16
16
17
17
@ BeforeClass
18
18
public static void setup () {
19
- test = new _583 ();
19
+ solution1 = new _583 . Solution1 ();
20
20
}
21
21
22
22
@ Test
23
23
public void test1 () {
24
24
word1 = "sea" ;
25
25
word2 = "eat" ;
26
- assertEquals (2 , test .minDistance (word1 , word2 ));
26
+ assertEquals (2 , solution1 .minDistance (word1 , word2 ));
27
27
}
28
28
29
29
@ Test
30
30
public void test2 () {
31
31
word1 = "sea" ;
32
32
word2 = "ate" ;
33
- assertEquals (4 , test .minDistance (word1 , word2 ));
33
+ assertEquals (4 , solution1 .minDistance (word1 , word2 ));
34
34
}
35
35
}
You can’t perform that action at this time.
0 commit comments