Given two strings text1 and text2, return the length of their longest common subsequence. The subsequence must appear in both strings in the same relative order, but it does not need to be contiguous. Pattern focus: LCS. This is the classic 2D DP formulation for subsequence matching.
text1 = first string, text2 = second string
length of the longest common subsequence
Example 1:
Input:
text1 = "abcde" text2 = "ace"
Output:
3
Explanation:
The LCS is ace.
Example 2:
Input:
text1 = "abc" text2 = "def"
Output:
0
Explanation:
The strings have no common subsequence.