编辑距离Edit Distance 非常典型的DP类型题目

https://leetcode.com/problems/edit-distance/?tab=Description

 

真的非常好,也非常典型。

https://discuss.leetcode.com/topic/17639/20ms-detailed-explained-c-solutions-o-n-space

 

dp[i][0] = i;
dp[0][j] = j;
dp[i][j] = dp[i - 1][j - 1], if word1[i - 1] = word2[j - 1];
dp[i][j] = min(dp[i - 1][j - 1] + 1, dp[i - 1][j] + 1, dp[i][j - 1] + 1), otherwise.

 

posted @ 2017-02-25 23:21  blcblc  阅读(617)  评论(0编辑  收藏  举报