java.lang.Object
g0701_0800.s0792_number_of_matching_subsequences.Solution

public class Solution extends Object
792 - Number of Matching Subsequences.<p>Medium</p> <p>Given a string <code>s</code> and an array of strings <code>words</code>, return <em>the number of</em> <code>words[i]</code> <em>that is a subsequence of</em> <code>s</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.</p> <ul> <li>For example, <code>&quot;ace&quot;</code> is a subsequence of <code>&quot;abcde&quot;</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcde&rdquo;, words = [&ldquo;a&rdquo;,&ldquo;bb&rdquo;,&ldquo;acd&rdquo;,&ldquo;ace&rdquo;]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> There are three strings in words that are a subsequence of s: &ldquo;a&rdquo;, &ldquo;acd&rdquo;, &ldquo;ace&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;dsahjpjauf&rdquo;, words = [&ldquo;ahjpjau&rdquo;,&ldquo;ja&rdquo;,&ldquo;ahbwzgqnuk&rdquo;,&ldquo;tnmlanowax&rdquo;]</p> <p><strong>Output:</strong> 2</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 5 * 10<sup>4</sup></code></li> <li><code>1 <= words.length <= 5000</code></li> <li><code>1 <= words[i].length <= 50</code></li> <li><code>s</code> and <code>words[i]</code> consist of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numMatchingSubseq

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