mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			1006 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			1006 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> word1 = "sea", word2 = "eat"
 | 
						|
<strong>Output:</strong> 2
 | 
						|
<strong>Explanation:</strong> You need one step to make "sea" to "ea" and another step to make "eat" to "ea".
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> word1 = "leetcode", word2 = "etco"
 | 
						|
<strong>Output:</strong> 4
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </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>
 |