|
| 1 | +# 1143. Longest Common Subsequence |
| 2 | + |
| 3 | +Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. |
| 4 | + |
| 5 | +A subsequence 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. |
| 6 | + |
| 7 | +For example, "ace" is a subsequence of "abcde". |
| 8 | +A common subsequence of two strings is a subsequence that is common to both strings. |
| 9 | + |
| 10 | + |
| 11 | +# Example 1: |
| 12 | + |
| 13 | +Input: text1 = "abcde", text2 = "ace" |
| 14 | +Output: 3 |
| 15 | +Explanation: The longest common subsequence is "ace" and its length is 3. |
| 16 | + |
| 17 | +## Example 2: |
| 18 | + |
| 19 | +Input: text1 = "abc", text2 = "abc" |
| 20 | +Output: 3 |
| 21 | +Explanation: The longest common subsequence is "abc" and its length is 3. |
| 22 | + |
| 23 | +## Example 3: |
| 24 | + |
| 25 | +Input: text1 = "abc", text2 = "def" |
| 26 | +Output: 0 |
| 27 | +Explanation: There is no such common subsequence, so the result is 0. |
| 28 | + |
| 29 | + |
| 30 | +## Constraints: |
| 31 | + |
| 32 | +1 <= text1.length, text2.length <= 1000 |
| 33 | +text1 and text2 consist of only lowercase English characters. |
0 commit comments