1092. Shortest Common Supersequence
1092. Shortest Common Supersequence
Description
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.
A string s
is a subsequence of string t
if deleting some number of characters from t
(possibly 0
) results in the string s
.
Example 1:
1 | Input: str1 = "abac", str2 = "cab" |
Example 2:
1 | Input: str1 = "aaaaaaaa", str2 = "aaaaaaaa" |
Constraints:
1 <= str1.length, str2.length <= 1000
str1
andstr2
consist of lowercase English letters.
Hints/Notes
- 2025/03/05 Q2
- dp
- 0x3Fâs solution
Solution
Language: C++
1 | class Solution { |