java.lang.Object
g2201_2300.s2255_count_prefixes_of_a_given_string.Solution

public class Solution extends Object
2255 - Count Prefixes of a Given String.<p>Easy</p> <p>You are given a string array <code>words</code> and a string <code>s</code>, where <code>words[i]</code> and <code>s</code> comprise only of <strong>lowercase English letters</strong>.</p> <p>Return <em>the <strong>number of strings</strong> in</em> <code>words</code> <em>that are a <strong>prefix</strong> of</em> <code>s</code>.</p> <p>A <strong>prefix</strong> of a string is a substring that occurs at the beginning of the string. A <strong>substring</strong> is a contiguous sequence of characters within a string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;,&ldquo;ab&rdquo;,&ldquo;bc&rdquo;,&ldquo;abc&rdquo;], s = &ldquo;abc&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>The strings in words which are a prefix of s = &ldquo;abc&rdquo; are:</p> <p>&ldquo;a&rdquo;, &ldquo;ab&rdquo;, and &ldquo;abc&rdquo;.</p> <p>Thus the number of strings in words which are a prefix of s is 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&ldquo;a&rdquo;], s = &ldquo;aa&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <p>Both of the strings are a prefix of s.</p> <p>Note that the same string can occur multiple times in words, and it should be counted each time.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words.length <= 1000</code></li> <li><code>1 <= words[i].length, s.length <= 10</code></li> <li><code>words[i]</code> and <code>s</code> consist of lowercase English letters <strong>only</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countPrefixes

      public int countPrefixes(String[] words, String s)