We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c6000a9 commit a035c59Copy full SHA for a035c59
cpp/_72.cpp
@@ -0,0 +1,26 @@
1
+
2
+//Problem Link : https://leetcode.com/problems/edit-distance/
3
+//Method : DP
4
5
+class Solution {
6
+public:
7
+ int minDistance(string word1, string word2) {
8
+ int n=word1.length();
9
+ int m=word2.length();
10
+ int dp[n+1][m+1];
11
+ for(int i=0;i<=n;i++){
12
+ for(int j=0;j<=m;j++){
13
+ if(i==0)
14
+ dp[i][j]=j;
15
+ else if(j==0)
16
+ dp[i][j]=i;
17
+ else if(word1[i-1]==word2[j-1])
18
+ dp[i][j]=dp[i-1][j-1];
19
+ else
20
+ dp[i][j]=1+min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1]));
21
22
+ }
23
24
+ return dp[n][m];
25
26
+};
0 commit comments