Easy short memoisation


#1
int findMinOperations(string A,string B,int i,int j,vector<vector<int>> &dp){
    if(i==0) return dp[i][j]=j;
    if(j==0) return dp[i][j]=i;
    if(dp[i][j]!=-1) return dp[i][j];
    if(A[i-1]==B[j-1]) dp[i][j]=findMinOperations(A,B,i-1,j-1,dp);
    else dp[i][j]=1+min({findMinOperations(A,B,i,j-1,dp),findMinOperations(A,B,i-1,j,dp),findMinOperations(A,B,i-1,j-1,dp)});
    return dp[i][j];
}
int Solution::minDistance(string A, string B) {
    vector<vector<int>> dp(A.size()+1,vector<int> (B.size()+1,-1));
    return findMinOperations(A,B,A.size(),B.size(),dp);
}