Второй пункт не проходит, но выводит все правильно
package com.javarush.task.task39.task3909;
/*
Одно изменение
*/
public class Solution {
public static void main(String[] args) {
}
public static boolean isOneEditAway(String first, String second) {
if (first.equals("") && second.equals("")) return true;
//The length is the same
if (first.length() == second.length()) {
if (first.equals(second)) return true;
int count = 0;
for (int i = 0; i < first.length(); i++) {
if (first.charAt(i) != second.charAt(i)){
count++;
}
}
if (count == 1){
return true;
} else {
return false;
}
}
int l = first.length() - second.length();
if (l > 1 || l < -1)
return false;
//The first line is longer
if (first.length() - second.length() == 1){
int count = 0;
for (int i = 0; i < first.length(); i++) {
char firstChar = first.charAt(i);
for (int j = 0; j < second.length(); j++) {
char secondChar = second.charAt(j);
if (firstChar == secondChar){
count++;
}
}
}
if (count == first.length() - 1){
return true;
} else {
return false;
}
}
//The second line is longer
if (second.length() - first.length() == 1){
int count = 0;
for (int i = 0; i < second.length(); i++) {
char secondChar = second.charAt(i);
for (int j = 0; j < first.length(); j++) {
char firstChar = first.charAt(j);
if (secondChar == firstChar){
count++;
}
}
}
if (count == second.length() - 1){
return true;
} else {
return false;
}
}
return false;
}
}