2800. Shortest String That Contains Three Strings Medium
1/**
2 * [2800] Shortest String That Contains Three Strings
3 *
4 * Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.
5 * If there are multiple such strings, return the lexicographically smallest one.
6 * Return a string denoting the answer to the problem.
7 * Notes
8 *
9 * A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
10 * A substring is a contiguous sequence of characters within a string.
11 *
12 *
13 * <strong class="example">Example 1:
14 *
15 * Input: a = "abc", b = "bca", c = "aaa"
16 * Output: "aaabca"
17 * Explanation: We show that "aaabca" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and "aaabca" is the lexicographically smallest one.
18 * <strong class="example">Example 2:
19 *
20 * Input: a = "ab", b = "ba", c = "aba"
21 * Output: "aba"
22 * Explanation: We show that the string "aba" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that "aba" is the lexicographically smallest one.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= a.length, b.length, c.length <= 100
28 * a, b, c consist only of lowercase English letters.
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/shortest-string-that-contains-three-strings/
34// discuss: https://leetcode.com/problems/shortest-string-that-contains-three-strings/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn minimum_string(a: String, b: String, c: String) -> String {
40 String::new()
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_2800() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.