Recursive solution solved


#1

#define in long long
in edid(in i,in j,in n,in m,string a,string b,vector<vector>& dp)
{
if(i>n&&j>m)
return 0;
else if(i>n)
return m-j+1;
else if(j>m)
return n-i+1;

    if(dp[i][j]==-1)
    {
        if(a[i]==b[j])
        dp[i][j]=edid(i+1,j+1,n,m,a,b,dp);
        else
        dp[i][j]=min(edid(i,j+1,n,m,a,b,dp),min(edid(i+1,j,n,m,a,b,dp),edid(i+1,j+1,n,m,a,b,dp)))+1;
        
    }
    return dp[i][j];

}
int Solution::minDistance(string a, string b) {
in n=a.size();
in m=b.size();
vector<vector> dp(n,vector(m,-1));
return int(edid(0,0,n-1,m-1,a,b,dp));
}