Class Solution

java.lang.Object
g1301_1400.s1397_find_all_good_strings.Solution

public class Solution extends Object
1397 - Find All Good Strings.<p>Hard</p> <p>Given the strings <code>s1</code> and <code>s2</code> of size <code>n</code> and the string <code>evil</code>, return <em>the number of <strong>good</strong> strings</em>.</p> <p>A <strong>good</strong> string has size <code>n</code>, it is alphabetically greater than or equal to <code>s1</code>, it is alphabetically smaller than or equal to <code>s2</code>, and it does not contain the string <code>evil</code> as a substring. Since the answer can be a huge number, return this <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 2, s1 = &ldquo;aa&rdquo;, s2 = &ldquo;da&rdquo;, evil = &ldquo;b&rdquo;</p> <p><strong>Output:</strong> 51</p> <p><strong>Explanation:</strong> There are 25 good strings starting with &lsquo;a&rsquo;: &ldquo;aa&rdquo;,&ldquo;ac&rdquo;,&ldquo;ad&rdquo;,&hellip;,&ldquo;az&rdquo;. Then there are 25 good strings starting with &lsquo;c&rsquo;: &ldquo;ca&rdquo;,&ldquo;cc&rdquo;,&ldquo;cd&rdquo;,&hellip;,&ldquo;cz&rdquo; and finally there is one good string starting with &lsquo;d&rsquo;: &ldquo;da&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 8, s1 = &ldquo;leetcode&rdquo;, s2 = &ldquo;leetgoes&rdquo;, evil = &ldquo;leet&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> All strings greater than or equal to s1 and smaller than or equal to s2 start with the prefix &ldquo;leet&rdquo;, therefore, there is not any good string.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 2, s1 = &ldquo;gx&rdquo;, s2 = &ldquo;gz&rdquo;, evil = &ldquo;x&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Constraints:</strong></p> <ul> <li><code>s1.length == n</code></li> <li><code>s2.length == n</code></li> <li><code>s1 <= s2</code></li> <li><code>1 <= n <= 500</code></li> <li><code>1 <= evil.length <= 50</code></li> <li>All strings consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findGoodStrings

      public int findGoodStrings(int n, String s1, String s2, String evil)