We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 821b88d commit f76cb31Copy full SHA for f76cb31
Day31.cpp
@@ -0,0 +1,30 @@
1
+/*
2
+ Author: Aryan Yadav
3
+ Edit Distance
4
+
5
+ Algorithm: DP
6
+ Difficulty: Medium
7
+*/
8
9
+class Solution {
10
+public:
11
+ int minDistance(string word1, string word2) {
12
+ int m = word1.length(), n = word2.length();
13
+ int dp[m+1][n+1];
14
15
+ for(int i = 0; i <= m; i++){
16
+ for(int j = 0; j <= n; j++){
17
+ if (i == 0){
18
+ dp[i][j] = j;
19
+ } else if (j == 0){
20
+ dp[i][j] = i;
21
+ } else if (word1[i - 1] == word2[j - 1]){
22
+ dp[i][j] = dp[i-1][j-1];
23
+ } else {
24
+ dp[i][j] = 1 + min(dp[i-1][j-1], min(dp[i][j-1], dp[i-1][j]));
25
+ }
26
27
28
+ return dp[m][n];
29
30
+};
0 commit comments