Longest Common Subsequence
Return the length of the longest sequence of characters appearing in both strings in the same order, possibly with gaps.
Example 1
text1 = "abcde"
text2 = "ace"3Explanation
a,c,e occur in both strings in order, giving length three.
Example 2
text1 = "abc"
text2 = "xyz"0Explanation
No character is shared, giving length zero.
Example 3
text1 = "aa"
text2 = "aaa"2Explanation
Only two a positions can be selected from the shorter string.
Constraints
- 1 <= each string length <= 1000
- Strings contain lowercase English letters
Function contract
longestCommonSubsequenceArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
"abcde""ace"