|
| 1 | +<h2><a href="https://leetcode.com/problems/edit-distance">72. Edit Distance</a></h2><h3>Medium</h3><hr><p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> |
| 2 | + |
| 3 | +<p>You have the following three operations permitted on a word:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>Insert a character</li> |
| 7 | + <li>Delete a character</li> |
| 8 | + <li>Replace a character</li> |
| 9 | +</ul> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> word1 = "horse", word2 = "ros" |
| 16 | +<strong>Output:</strong> 3 |
| 17 | +<strong>Explanation:</strong> |
| 18 | +horse -> rorse (replace 'h' with 'r') |
| 19 | +rorse -> rose (remove 'r') |
| 20 | +rose -> ros (remove 'e') |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> word1 = "intention", word2 = "execution" |
| 27 | +<strong>Output:</strong> 5 |
| 28 | +<strong>Explanation:</strong> |
| 29 | +intention -> inention (remove 't') |
| 30 | +inention -> enention (replace 'i' with 'e') |
| 31 | +enention -> exention (replace 'n' with 'x') |
| 32 | +exention -> exection (replace 'n' with 'c') |
| 33 | +exection -> execution (insert 'u') |
| 34 | +</pre> |
| 35 | + |
| 36 | +<p> </p> |
| 37 | +<p><strong>Constraints:</strong></p> |
| 38 | + |
| 39 | +<ul> |
| 40 | + <li><code>0 <= word1.length, word2.length <= 500</code></li> |
| 41 | + <li><code>word1</code> and <code>word2</code> consist of lowercase English letters.</li> |
| 42 | +</ul> |
0 commit comments