Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minDistance(string word1, string word2) {
- int l1 = word1.length();
- int l2 = word2.length();
- int dp[l1+1][l2+1];
- for(int i=0;i<l1+1;i++)
- {
- for(int j=0;j<l2+1;j++)
- {
- if(i==0)
- {
- dp[i][j]=j;continue;
- }
- if(j==0)
- {
- dp[i][j]=i;continue;
- }
- if(word1[i-1]==word2[j-1])
- {
- dp[i][j]=dp[i-1][j-1];continue;
- }
- dp[i][j]=1+min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]));
- }
- }
- return dp[l1][l2];
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement