Description
Given an array of unique strings words, return the shortest string that contains each string in words as a substring.
Examples
Input:
words = ["alex","loves","leetcode"]Output:
"alexlovesleetcode"Explanation:
Shortest superstring.
Input:
words = ["cat","dog","tcat","tcatdog"]Output:
tcatdogExplanation:
"tcatdog" contains all other words as substrings, making it the shortest superstring.
Input:
words = ["ab","bc","cd"]Output:
abcdExplanation:
Overlapping "ab" with "bc" (sharing 'b') and "bc" with "cd" (sharing 'c') creates the superstring "abcd".
Constraints
- •
1 ≤ words.length ≤ 12