Тестировала. Всё работает. Что может не нравиться?
package com.javarush.task.task39.task3909;
/*
Одно изменение
*/
public class Solution {
public static void main(String[] args) {
}
public static boolean isOneEditAway(String first, String second) {
if (Math.abs(first.length() - second.length()) > 1) return false;
int index = 0;
while (index < Math.min(first.length(), second.length())) {
if (first.charAt(index) != second.charAt(index)) {
return checkAgain(first, second, index);
}
index++;
}
return true;
}
private static boolean checkAgain(String first, String second, int index) {
if (first.charAt(index) == second.charAt(index + 1) && second.length() - first.length() == 1) {
for (int i = index; i < first.length(); i++) {
if (first.charAt(i) != second.charAt(i + 1)) return false;
}
return true;
} else if (second.charAt(index) == first.charAt(index + 1) && first.length() - second.length() == 1) {
for (int i = index; i < second.length(); i++) {
if (second.charAt(i) != first.charAt(i + 1)) return false;
}
return true;
} else if (first.charAt(index + 1) == second.charAt(index + 1) && first.length() == second.length()) {
for (int i = index + 1; i < first.length(); i++) {
if (first.charAt(i) != second.charAt(i)) return false;
}
return true;
}
return false;
}
}