Skip to content

Commit b5f81e7

Browse files
committed
Simplify StringTransformation solution (again)
1 parent eba9c9c commit b5f81e7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/main/java/by/andd3dfx/string/StringTransformation.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,17 @@ public static boolean couldTransform(String first, String second) {
4343
return true;
4444
}
4545

46+
// Lengths differ by 1 - need to remove/add one character
4647
var pos = 0;
47-
while (pos < len1 && pos < len2) { // Lengths differ by 1 - need to remove/add one character
48-
if (s1[pos] == s2[pos]) {
49-
pos++;
50-
continue;
51-
}
48+
while (pos < len1 && pos < len2 && s1[pos] == s2[pos]) {
49+
pos++;
50+
}
5251

53-
if (pos + 1 < len1 && s1[pos + 1] == s2[pos]) {
54-
return remainingPartsShouldBeEqual(first, pos + 1, second, pos);
55-
}
56-
if (pos + 1 < len2 && s1[pos] == s2[pos + 1]) {
57-
return remainingPartsShouldBeEqual(first, pos, second, pos + 1);
58-
}
52+
if (pos + 1 < len1 && s1[pos + 1] == s2[pos]) {
53+
return remainingPartsShouldBeEqual(first, pos + 1, second, pos);
54+
}
55+
if (pos + 1 < len2 && s1[pos] == s2[pos + 1]) {
56+
return remainingPartsShouldBeEqual(first, pos, second, pos + 1);
5957
}
6058
return true;
6159
}

0 commit comments

Comments
 (0)