java.lang.Object
g2101_2200.s2185_counting_words_with_a_given_prefix.Solution

public class Solution extends Object
2185 - Counting Words With a Given Prefix.<p>Easy</p> <p>You are given an array of strings <code>words</code> and a string <code>pref</code>.</p> <p>Return <em>the number of strings in</em> <code>words</code> <em>that contain</em> <code>pref</code> <em>as a <strong>prefix</strong></em>.</p> <p>A <strong>prefix</strong> of a string <code>s</code> is any leading contiguous substring of <code>s</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;pay&rdquo;,&ldquo;<strong>at</strong>tention&rdquo;,&ldquo;practice&rdquo;,&ldquo;<strong>at</strong>tend&rdquo;], <code>pref</code> = &ldquo;at&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The 2 strings that contain &ldquo;at&rdquo; as a prefix are: &ldquo;<strong>at</strong>tention&rdquo; and &ldquo;<strong>at</strong>tend&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;leetcode&rdquo;,&ldquo;win&rdquo;,&ldquo;loops&rdquo;,&ldquo;success&rdquo;], <code>pref</code> = &ldquo;code&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There are no strings that contain &ldquo;code&rdquo; as a prefix.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words.length <= 100</code></li> <li><code>1 <= words[i].length, pref.length <= 100</code></li> <li><code>words[i]</code> and <code>pref</code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • prefixCount

      public int prefixCount(String[] words, String pref)