java.lang.Object
g0501_0600.s0583_delete_operation_for_two_strings.Solution

public class Solution extends Object
583 - Delete Operation for Two Strings.<p>Medium</p> <p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of <strong>steps</strong> required to make</em> <code>word1</code> <em>and</em> <code>word2</code> <em>the same</em>.</p> <p>In one <strong>step</strong> , you can delete exactly one character in either string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> word1 = &ldquo;sea&rdquo;, word2 = &ldquo;eat&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> You need one step to make &ldquo;sea&rdquo; to &ldquo;ea&rdquo; and another step to make &ldquo;eat&rdquo; to &ldquo;ea&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word1 = &ldquo;leetcode&rdquo;, word2 = &ldquo;etco&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= word1.length, word2.length <= 500</code></li> <li><code>word1</code> and <code>word2</code> consist of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minDistance

      public int minDistance(String word1, String word2)