1397. Find All Good Strings Hard
1/**
2 * [1397] Find All Good Strings
3 *
4 * Given the strings s1 and s2 of size n and the string evil, return the number of good strings.
5 * A good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, return this modulo 10^9 + 7.
6 *
7 * Example 1:
8 *
9 * Input: n = 2, s1 = "aa", s2 = "da", evil = "b"
10 * Output: 51
11 * Explanation: There are 25 good strings starting with 'a': "aa","ac","ad",...,"az". Then there are 25 good strings starting with 'c': "ca","cc","cd",...,"cz" and finally there is one good string starting with 'd': "da".
12 *
13 * Example 2:
14 *
15 * Input: n = 8, s1 = "leetcode", s2 = "leetgoes", evil = "leet"
16 * Output: 0
17 * Explanation: All strings greater than or equal to s1 and smaller than or equal to s2 start with the prefix "leet", therefore, there is not any good string.
18 *
19 * Example 3:
20 *
21 * Input: n = 2, s1 = "gx", s2 = "gz", evil = "x"
22 * Output: 2
23 *
24 *
25 * Constraints:
26 *
27 * s1.length == n
28 * s2.length == n
29 * s1 <= s2
30 * 1 <= n <= 500
31 * 1 <= evil.length <= 50
32 * All strings consist of lowercase English letters.
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/find-all-good-strings/
38// discuss: https://leetcode.com/problems/find-all-good-strings/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn find_good_strings(n: i32, s1: String, s2: String, evil: String) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1397() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.