mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										42
									
								
								算法题(国外版)/longest-common-subsequence.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								算法题(国外版)/longest-common-subsequence.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p>
 | 
			
		||||
 | 
			
		||||
<p>A <strong>subsequence</strong> of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.</p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li>For example, <code>"ace"</code> is a subsequence of <code>"abcde"</code>.</li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
<p>A <strong>common subsequence</strong> of two strings is a subsequence that is common to both strings.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> text1 = "abcde", text2 = "ace" 
 | 
			
		||||
<strong>Output:</strong> 3  
 | 
			
		||||
<strong>Explanation:</strong> The longest common subsequence is "ace" and its length is 3.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> text1 = "abc", text2 = "abc"
 | 
			
		||||
<strong>Output:</strong> 3
 | 
			
		||||
<strong>Explanation:</strong> The longest common subsequence is "abc" and its length is 3.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 3:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> text1 = "abc", text2 = "def"
 | 
			
		||||
<strong>Output:</strong> 0
 | 
			
		||||
<strong>Explanation:</strong> There is no such common subsequence, so the result is 0.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><code>1 <= text1.length, text2.length <= 1000</code></li>
 | 
			
		||||
	<li><code>text1</code> and <code>text2</code> consist of only lowercase English characters.</li>
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user