@@ -0,0 +1,933 @@
+package problems;%0A%0Apublic class EditDistance %7B%0A    public int minDistance(String word1, String word2) %7B%0A        if (word1 == null %7C%7C word2 == null)%0A            return 0;%0A        %0A        int n1 = word1.length(), n2 = word2.length();%0A        int%5B%5D%5B%5D d = new int%5Bn1 + 1%5D%5Bn2 + 1%5D;%0A        for (int i = 1; i %3C= n1; i++)%0A            d%5Bi%5D%5B0%5D = i;%0A        for (int i = 1; i %3C= n2; i++)%0A            d%5B0%5D%5Bi%5D = i;%0A        for (int i = 1; i %3C= n1; i++) %7B%0A            for (int j = 1; j %3C= n2; j++) %7B%0A                int min = Math.min(d%5Bi - 1%5D%5Bj - 1%5D, Math.min(d%5Bi - 1%5D%5Bj%5D, d%5Bi%5D%5Bj - 1%5D));%0A                d%5Bi%5D%5Bj%5D = word1.charAt(i - 1) == word2.charAt(j - 1) ? d%5Bi - 1%5D%5Bj - 1%5D : min + 1;%0A            %7D%0A        %7D%0A        return d%5Bn1%5D%5Bn2%5D;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        EditDistance ed = new EditDistance();%0A        %0A        String s1 = %22ab%22, s2 = %22bc%22;%0A        System.out.println(ed.minDistance(s1, s2));%0A    %7D%0A%7D%0A

Add Edit Distance