1143. Longest Common Subsequence Medium
1/**
2 * [1143] Longest Common Subsequence
3 *
4 * Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.
5 * A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
6 *
7 * For example, "ace" is a subsequence of "abcde".
8 *
9 * A common subsequence of two strings is a subsequence that is common to both strings.
10 *
11 * Example 1:
12 *
13 * Input: text1 = "abcde", text2 = "ace"
14 * Output: 3
15 * Explanation: The longest common subsequence is "ace" and its length is 3.
16 *
17 * Example 2:
18 *
19 * Input: text1 = "abc", text2 = "abc"
20 * Output: 3
21 * Explanation: The longest common subsequence is "abc" and its length is 3.
22 *
23 * Example 3:
24 *
25 * Input: text1 = "abc", text2 = "def"
26 * Output: 0
27 * Explanation: There is no such common subsequence, so the result is 0.
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= text1.length, text2.length <= 1000
33 * text1 and text2 consist of only lowercase English characters.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/longest-common-subsequence/
39// discuss: https://leetcode.com/problems/longest-common-subsequence/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1143() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.