Practice/LinkedIn/Leetcode 72. Edit Distance
CodingMust
Given two strings, determine the minimum number of operations required to transform the first string into the second string. You can perform three types of operations on a character:
Your task is to compute the smallest number of these operations needed to convert word1 into word2.
0 <= word1.length, word2.length <= 500Example 1:
Input: word1 = "horse", word2 = "ros" Output: 3 Explanation: horse -> rorse (replace 'h' with 'r') rorse -> rose (delete 'r') rose -> ros (delete 'e') Total: 3 operations
Example 2:
Input: word1 = "saturday", word2 = "sunday" Output: 3 Explanation: saturday -> sturday (delete 'a') sturday -> sunday (replace 't' with 'n') sunday -> sunday (delete 'r') Total: 3 operations
Example 3:
Input: word1 = "", word2 = "a" Output: 1 Explanation: Insert character 'a'