java.lang.Object
g1601_1700.s1684_count_the_number_of_consistent_strings.Solution

public class Solution extends Object
1684 - Count the Number of Consistent Strings.<p>Easy</p> <p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent</strong> if all characters in the string appear in the string <code>allowed</code>.</p> <p>Return <em>the number of <strong>consistent</strong> strings in the array</em> <code>words</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> allowed = &ldquo;ab&rdquo;, words = [&ldquo;ad&rdquo;,&ldquo;bd&rdquo;,&ldquo;aaab&rdquo;,&ldquo;baa&rdquo;,&ldquo;badab&rdquo;]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Strings &ldquo;aaab&rdquo; and &ldquo;baa&rdquo; are consistent since they only contain characters &lsquo;a&rsquo; and &lsquo;b&rsquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> allowed = &ldquo;abc&rdquo;, words = [&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;,&ldquo;ab&rdquo;,&ldquo;ac&rdquo;,&ldquo;bc&rdquo;,&ldquo;abc&rdquo;]</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> All strings are consistent.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> allowed = &ldquo;cad&rdquo;, words = [&ldquo;cc&rdquo;,&ldquo;acd&rdquo;,&ldquo;b&rdquo;,&ldquo;ba&rdquo;,&ldquo;bac&rdquo;,&ldquo;bad&rdquo;,&ldquo;ac&rdquo;,&ldquo;d&rdquo;]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> Strings &ldquo;cc&rdquo;, &ldquo;acd&rdquo;, &ldquo;ac&rdquo;, and &ldquo;d&rdquo; are consistent.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words.length <= 10<sup>4</sup></code></li> <li><code>1 <= allowed.length <= 26</code></li> <li><code>1 <= words[i].length <= 10</code></li> <li>The characters in <code>allowed</code> are <strong>distinct</strong>.</li> <li><code>words[i]</code> and <code>allowed</code> contain only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countConsistentStrings

      public int countConsistentStrings(String allowed, String[] words)