Why this solution is wrong?


  • 0
     int minDistance(string word1, string word2) {
            int len1 = word1.length();
            int len2 = word2.length();
            
            int commonLen = 0;
            
            vector<int> L(len2 + 1, 0);
            
            for(int m = 0; m < len1; ++m)
            {
                for(int n = 0; n < len2; ++n)
                {
                    if(word1[m] == word2[n]) L[n + 1] = L[n] + 1;
                    else if(word1[m] != word2[n])
                    {
                        L[n + 1] = max(L[n], L[n + 1]);
                    }
                }
                
            }
            
            commonLen = L[len2];
            
            return len1 + len2 - 2 * commonLen;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.