rewrite leetcode edit distance