@@ -0,0 +1,966 @@
+package problems;%0A%0Apublic class OneEditDistance %7B%0A    public boolean oneEdit(String A, String B) %7B%0A        if (A == null %7C%7C B == null)%0A            return false;%0A        final int n1 = A.length(), n2 = B.length();%0A        if (Math.abs(n1 - n2) %3E 1)%0A            return false;%0A%0A        final int%5B%5D T = %7B 1, 0, 1 %7D;%0A        for (int i = 0; i %3C n2; i++) %7B%0A            if (i == 0 %7C%7C A.charAt(i - 1) != B.charAt(i))%0A                T%5B0%5D = T%5B1%5D + 1;%0A            if (i %3E= n1)%0A                return T%5B0%5D %3C 2;%0A%0A            if (A.charAt(i) != B.charAt(i))%0A                T%5B1%5D = Math.min(T%5B0%5D, Math.min(T%5B1%5D, T%5B2%5D)) + 1;%0A%0A            if (i + 1 %3E= n1 %7C%7C A.charAt(i + 1) != B.charAt(i))%0A                T%5B2%5D = T%5B1%5D + 1;%0A        %7D%0A        return T%5B1%5D %3C 2 %7C%7C T%5B2%5D %3C 2;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        OneEditDistance oe = new OneEditDistance();%0A%0A        String A = %22adc%22;%0A        String B = %22adbc%22;%0A        System.out.println(oe.oneEdit(A, B));%0A    %7D%0A%7D%0A

Add One Edit Distance