You are given two strings, text1 and text2. Find the longest string that is a subsequence of both of them, and return its length. If they have no common subsequence, return 0.
A subsequence is a string made by deleting some characters (maybe none) from another string, without changing the order of the rest.
Examples
Example 1:
Input: text1 = "trains", text2 = "rain"
Output: 4
Explanation: The string "rain" can be taken from both. Its length is 4.
Example 2:
Input: text1 = "stone", text2 = "notes"
Output: 2
Explanation: One longest common subsequence is "te". Its length is 2.
Example 3:
Input: text1 = "ab", text2 = "cd"
Output: 0
Explanation: The two strings share no character, so the answer is 0.