How to find the longest common subsequence of leetcode
Editor to share with you how to find the longest common subsequence of leetcode, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Given the two strings text1 and text2, the longest common subsequence of the two strings is returned.
A subsequence of a string is a new string made up of the original string after deleting some characters (or no characters) without changing the relative order of the characters.
For example, "ace" is a subsequence of "abcde", but "aec" is not a subsequence of "abcde". The "common subsequence" of two strings is the subsequence shared by the two strings.
If the two strings have no common subsequence, 0 is returned.
Example 1:
Input: text1 = "abcde", text2 = "ace" output: 3 explanation: the longest common subsequence is "ace", its length is 3. Example 2:
Input: text1 = "abc", text2 = "abc" output: 3 explanation: the longest common subsequence is "abc", its length is 3. Example 3:
Input: text1 = "abc", text2 = "def" output: 0 explanation: two strings do not have a common subsequence, return 0.
Tip:
one