Class Solution

java.lang.Object
g0101_0200.s0115_distinct_subsequences.Solution

public class Solution extends Object
115 - Distinct Subsequences.<p>Hard</p> <p>Given two strings <code>s</code> and <code>t</code>, return <em>the number of distinct subsequences of <code>s</code> which equals <code>t</code></em>.</p> <p>A string&rsquo;s <strong>subsequence</strong> is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters&rsquo; relative positions. (i.e., <code>&quot;ACE&quot;</code> is a subsequence of <code>&quot;ABCDE&quot;</code> while <code>&quot;AEC&quot;</code> is not).</p> <p>It is guaranteed the answer fits on a 32-bit signed integer.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;rabbbit&rdquo;, t = &ldquo;rabbit&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> As shown below, there are 3 ways you can generate &ldquo;rabbit&rdquo; from S. <code>**rabb**b**it**</code> <code>**ra**b**bbit**</code> <code>**rab**b**bit**</code></p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;babgbag&rdquo;, t = &ldquo;bag&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> As shown below, there are 5 ways you can generate &ldquo;bag&rdquo; from S. <code>**ba**b**g**bag</code> <code>**ba**bgba**g**</code> <code>**b**abgb**ag**</code> <code>ba**b**gb**ag**</code> <code>babg**bag**</code></p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length, t.length <= 1000</code></li> <li><code>s</code> and <code>t</code> consist of English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numDistinct

      public int numDistinct(String text, String text2)