Skip to content

Commit b8105a1

Browse files
author
Chirag Shah
committed
Added day30 and day31 solution
1 parent 9700c03 commit b8105a1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
int minDistance(string word1, string word2) {
4+
5+
int M = word1.size(), N = word2.size();
6+
7+
vector<vector<int>> dp(M + 1, vector<int> (N + 1, 0));
8+
9+
for(int i=1; i<=M; i++)
10+
dp[i][0] = i;
11+
12+
for(int j=1; j<=N; j++)
13+
dp[0][j] = j;
14+
15+
16+
for(int i=1; i<=M; i++){
17+
for(int j=1; j<=N; j++){
18+
19+
if(word1[i-1] == word2[j-1])
20+
dp[i][j] = dp[i-1][j-1];
21+
else{
22+
dp[i][j] = min(dp[i-1][j], min(dp[i][j-1], dp[i-1][j-1])) + 1;
23+
}
24+
25+
}
26+
}
27+
return dp[M][N];
28+
}
29+
};

0 commit comments

Comments
 (0)