Python 3   ||   8 lines,  w/ comments   ||   T/S: 95% / 93%
\nclass Solution:\n    def minDistance(self, word1: str, word2: str) -> int:\n\n        w1, w2 = len(word1), len(word2)\n        \n        @lru_cache(None)\n   
```\nclass Solution:\n    def minDistance(self, word1: str, word2: str) -> int:\n\n        w1, w2 = len(word1), len(word2)\n        \n        @lru_cache(None)\n        def dp(i, j):\n\n            if i >= w1             : return w2-j                # word1 used up, so all inserts\n            if j >= w2             : return w1-i                # word2 used up, so all deletes\n            if word1[i] == word2[j]: return dp(i+1, j+1)        # letters match, so no operation\n\n            return min(dp(i,j+1), dp(i+1,j), dp(i+1,j+1)) + 1   # insert, delete, replace\n\n        return dp(0,0)\n```\n[https://leetcode.com/problems/edit-distance/submissions/611008842/](https://leetcode.com/problems/edit-distance/submissions/611008842/)\n\nI could be wrong, but I think that time complexity is *O*(*MN*) and space complexity is *O*(*MN*), in which *M, N* ~ `len(word1),len(word2)`.\n
['Python3']