A subsequence of a string is obtained by deleting zero or more characters without changing the order of the remaining ones: "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence of both.
Return the length of the longest common subsequence of s and t, or 0 if they have none.
Examples
Example 1
Input: s = "abcde", t = "ace"
Output: 3
Explanation: "ace" is a subsequence of both strings.
Example 2
Input: s = "abc", t = "abc"
Output: 3
Explanation: The whole string is common.
Example 3
Input: s = "abc", t = "def"
Output: 0
Explanation: The strings share no character.
Constraints
1≤s.length, t.length≤1000
s and t consist of lowercase English letters only
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run