Given an array A of strings, find any smallest string that contains each string in A as a substring.
We may assume that no string in A is substring of another string in A.
Example
No.1
Input: [“alex”,”loves”,”leetcode”]
Output: “alexlovesleetcode”
Explanation: All permutations of “alex”,”loves”,”leetcode” would also be accepted.
No.2
Input: [“catg”,”ctaagt”,”gcta”,”ttca”,”atgcatc”]
Output: “gctaagttcatgcatc”
Note
- 1 <= A.length <= 12
- 1 <= A[i].length <= 20
Code
1 | // cost[i][j]: the cost of appending A[j] after A[i] |