Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit35e2d66

Browse files
fix build
1 parent315090b commit35e2d66

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

‎src/main/java/com/fishercoder/solutions/_72.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,35 @@ public int minDistance(String word1, String word2) {
3737
returntable[m][n];
3838
}
3939
}
40-
publicstaticclassSolution2{
40+
41+
publicstaticclassSolution2 {
4142
publicintminDistance(Stringword1,Stringword2) {
4243
// using levenshtein Distance to find minimum transformation operations required from word 1 to word 2
4344
int[][]dp =newint[word1.length()][word2.length()];
4445
// fill the dp array with -1 value
45-
for(int[]rows :dp){
46+
for(int[]rows :dp){
4647
Arrays.fill(rows, -1);
4748
}
48-
returnlevenshteinDistance(word1,word1.length()-1,word2,word2.length()-1,dp);
49+
returnlevenshteinDistance(word1,word1.length() -1,word2,word2.length() -1,dp);
4950
}
50-
privateintlevenshteinDistance(Strings1,ints1Index,Strings2,ints2Index,int[][]dp){
5151

52-
if(s1Index <0){// when s1 is "" perform all insertions to get s1 to s2
52+
privateintlevenshteinDistance(Strings1,ints1Index,Strings2,ints2Index,int[][]dp) {
53+
54+
if (s1Index <0) {// when s1 is "" perform all insertions to get s1 to s2
5355
returns2Index +1;
54-
}
55-
elseif(s2Index <0) {// when s2 is "" perform all deletions from s1
56+
}elseif (s2Index <0) {// when s2 is "" perform all deletions from s1
5657
returns1Index +1;
5758
}
5859

5960
// base condition when dp array is filled, return the distance
60-
if(dp[s1Index][s2Index] != -1)
61+
if(dp[s1Index][s2Index] != -1) {
6162
returndp[s1Index][s2Index];
63+
}
6264

63-
if(s1.charAt(s1Index) ==s2.charAt(s2Index)){
65+
if(s1.charAt(s1Index) ==s2.charAt(s2Index)){
6466
// Characters match, no edit distance to be calculated
6567
dp[s1Index][s2Index] =levenshteinDistance(s1,s1Index -1,s2,s2Index -1,dp);
66-
}
67-
else{
68+
}else {
6869
// When there is a character mismatch, perform operations
6970

7071
// Insertion

‎src/test/java/com/fishercoder/_72Test.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class _72Test {
1313

1414
@BeforeClass
1515
publicstaticvoidsetup() {
16-
solution1 =new_72.Solution1();solution2 =new_72.Solution2();
16+
solution1 =new_72.Solution1();
17+
solution2 =new_72.Solution2();
1718
}
1819

1920
@Test
@@ -25,4 +26,14 @@ public void test1() {
2526
publicvoidtest2() {
2627
assertEquals(5,solution1.minDistance("Ashmi","Chheda"));
2728
}
29+
30+
@Test
31+
publicvoidtest3() {
32+
assertEquals(1,solution2.minDistance("Ada","Adam"));
33+
}
34+
35+
@Test
36+
publicvoidtest4() {
37+
assertEquals(5,solution2.minDistance("Ashmi","Chheda"));
38+
}
2839
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp