mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given two strings <code>s</code> and <code>t</code> consisting of only lowercase English letters.</p>
 | 
						|
 | 
						|
<p>Return <em>the minimum number of characters that need to be appended to the end of </em><code>s</code><em> so that </em><code>t</code><em> becomes a <strong>subsequence</strong> of </em><code>s</code>.</p>
 | 
						|
 | 
						|
<p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "coaching", t = "coding"
 | 
						|
<strong>Output:</strong> 4
 | 
						|
<strong>Explanation:</strong> Append the characters "ding" to the end of s so that s = "coachingding".
 | 
						|
Now, t is a subsequence of s ("<u><strong>co</strong></u>aching<u><strong>ding</strong></u>").
 | 
						|
It can be shown that appending any 3 characters to the end of s will never make t a subsequence.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "abcde", t = "a"
 | 
						|
<strong>Output:</strong> 0
 | 
						|
<strong>Explanation:</strong> t is already a subsequence of s ("<u><strong>a</strong></u>bcde").
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "z", t = "abcde"
 | 
						|
<strong>Output:</strong> 5
 | 
						|
<strong>Explanation:</strong> Append the characters "abcde" to the end of s so that s = "zabcde".
 | 
						|
Now, t is a subsequence of s ("z<u><strong>abcde</strong></u>").
 | 
						|
It can be shown that appending any 4 characters to the end of s will never make t a subsequence.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= s.length, t.length <= 10<sup>5</sup></code></li>
 | 
						|
	<li><code>s</code> and <code>t</code> consist only of lowercase English letters.</li>
 | 
						|
</ul>
 |