def solution1(word1: str, word2: str):
    """
    计算编辑距离
    Args:
        word1 (str): 字符串1
        word2 (str): 字符串2

    Returns: (int) distance
    """
    if not word1 or not word2:
        return max(len(word1), len(word2))
    if word1 == word2:
        return 0
    res = []
    for i in range(len(word1) + 1):
        line_res = []
        for j in range(len(word2) + 1):
            if i == 0:
                line_res.append(j)
                continue
            if j == 0:
                line_res.append(i)
            else:
                if word1[i - 1] == word2[j - 1]:
                    line_res.append(res[i - 1][j - 1])
                else:
                    temp_dis = min(res[i - 1][j - 1], res[i - 1][j], line_res[j - 1]) + 1
                    line_res.append(temp_dis)
        res.append(line_res)
    return res[-1][-1]