Java || DP (Tabulation)
\n Describe your first thoughts on how to solve this problem. \n\n\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity: O(m * n
\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(m * n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m * n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minDistance(String word1, String word2) {\n        int m = word1.length();\n        int n = word2.length();\n\n        int[][] dp = new int[m + 1][n + 1];\n        int ans;\n\n        for(int i = 0; i <= m; i++){\n            dp[i][0] = i;\n        }\n        for(int i = 0; i <= n; i++){\n            dp[0][i] = i;\n        }\n\n        for(int i = 1; i <= m; i++){\n            for(int j = 1; j <= n; j++){\n                ans = dp[i - 1][j - 1];\n\n                if(word1.charAt(m - i) != word2.charAt(n - j)){\n                    ans = 1 + Math.min(ans, Math.min(dp[i][j - 1], dp[i - 1][j]));\n                }\n\n                dp[i][j] = ans;\n            }\n        }\n        return dp[m][n];\n    }\n}\n```
['Java']