Class Solution
-
- All Implemented Interfaces:
public final class Solution
1092 - Shortest Common Supersequence\.
Hard
Given two strings
str1
andstr2
, return the shortest string that has bothstr1
andstr2
as subsequences. If there are multiple valid strings, return any of them.A string
s
is a subsequence of stringt
if deleting some number of characters fromt
(possibly0
) results in the strings
.Example 1:
Input: str1 = "abac", str2 = "cab"
Output: "cabac"
Explanation:
str1 = "abac" is a subsequence of "cabac" because we can delete the first "c".
str2 = "cab" is a subsequence of "cabac" because we can delete the last "ac".
The answer provided is the shortest such string that satisfies these properties.
Example 2:
Input: str1 = "aaaaaaaa", str2 = "aaaaaaaa"
Output: "aaaaaaaa"
Constraints:
1 <= str1.length, str2.length <= 1000
str1
andstr2
consist of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final String
shortestCommonSupersequence(String str1, String str2)
-
-
Method Detail
-
shortestCommonSupersequence
final String shortestCommonSupersequence(String str1, String str2)
-
-
-
-