public static int minDistance(String word1, String word2) {
        if (word1 == null || word2 == null) {
            return 0;
        }
        int length1 = word1.length();
        int length2 = word2.length();
        if (length1 == 0) {
            return length2;
        }
        if (length2 == 0) {
            return length1;
        }

        int[][] ed = new int[length1 + 1][length2 + 1];
        for (int i = 0; i <= length1; i++) {
            ed[i][0] = i;
        }
        for (int i = 0; i <= length2; i++) {
            ed[0][i] = i;
        }
        for (int i = 1; i <= length1; i++) {
            char ch1 = word1.charAt(i - 1);
            for (int j = 1; j <= length2; j++) {
                char ch2 = word2.charAt(j - 1);
                ed[i][j] = Math.min(Math.min(ed[i - 1][j] + 1, ed[i][j - 1] + 1), ed[i - 1][j - 1]
                        + (ch1 == ch2 ? 0 : 1));
            }
        }
        return ed[length1][length2];
    }