My DP solution in C++ with comments.
\n\n    int minDistance(string word1, string word2) {\n        // DP talbe, i is the position in word1, and j is the position in word2\n        vector> distance
   \n\n    int minDistance(string word1, string word2) {\n        // DP talbe, i is the position in word1, and j is the position in word2\n        vector<vector<int>> distance(word1.length()+1, vector<int>(word2.length()+1, 0));\n        \n        // when i or j=0 means empty string, the distance is the length of another string\n        for(int i=0; i<distance.size(); i++)\n            for(int j=0; j< distance[0].size();j++){\n                if(i == 0)\n                    distance[i][j] = j;\n                else if(j == 0)\n                    distance[i][j] = i;\n            }\n        \n        // if word1[i]==word2[j], then the distance of i and j is the previous i and j\n        // otherwise we either replace, insert or delete a char\n        // when insert a char to word1 it means we are trying to match word1 at i-1 to word2 at j\n        // when delete a char from word1 it equals to insert a char to word2, which\n        // means we are trying to match word1 at i to word2 at j-1\n        // when replace a char to word1, then we add one step to previous i and j\n        for(int i=1; i< distance.size(); i++)\n            for(int j=1; j<distance[0].size(); j++){\n                if(word1[i-1] == word2[j-1])\n                    distance[i][j] = distance[i-1][j-1];\n                else\n                    distance[i][j] = 1+ min(distance[i-1][j-1], min(distance[i-1][j], distance[i][j-1]));\n            }\n            \n        return distance[word1.length()][word2.length()];\n    }
[]