1092. Shortest Common Supersequence Hard

@problem@discussion
#String#Dynamic Programming



1/**
2 * [1092] Shortest Common Supersequence 
3 *
4 * Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.
5 * A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.
6 *  
7 * Example 1:
8 * 
9 * Input: str1 = "abac", str2 = "cab"
10 * Output: "cabac"
11 * Explanation: 
12 * str1 = "abac" is a subsequence of "cabac" because we can delete the first "c".
13 * str2 = "cab" is a subsequence of "cabac" because we can delete the last "ac".
14 * The answer provided is the shortest such string that satisfies these properties.
15 * 
16 * Example 2:
17 * 
18 * Input: str1 = "aaaaaaaa", str2 = "aaaaaaaa"
19 * Output: "aaaaaaaa"
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= str1.length, str2.length <= 1000
25 * 	str1 and str2 consist of lowercase English letters.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/shortest-common-supersequence/
31// discuss: https://leetcode.com/problems/shortest-common-supersequence/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn shortest_common_supersequence(str1: String, str2: String) -> String {
37        String::new()
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_1092() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.