Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    115 - Distinct Subsequences.

    Hard

    Given two strings s and t, return the number of distinct subsequences of s which equals t.

    A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions. (i.e., "ACE" is a subsequence of "ABCDE" while "AEC" is not).

    The test cases are generated so that the answer fits on a 32-bit signed integer.

    Example 1:

    Input: s = "rabbbit", t = "rabbit"

    Output: 3

    Explanation: As shown below, there are 3 ways you can generate "rabbit" from s. <code><ins>rabb</ins>b<ins>it</ins></code> <code><ins>ra</ins>b<ins>bbit</ins></code> <code><ins>rab</ins>b<ins>bit</ins></code>

    Example 2:

    Input: s = "babgbag", t = "bag"

    Output: 5

    Explanation: As shown below, there are 5 ways you can generate "bag" from s. <code><ins>ba</ins>b<ins> g </ins>bag</code> <code><ins>ba</ins>bgba<ins>g</ins></code> <code><ins> b </ins>abgb**<ins>ag</ins></code> <code>ba<ins> b </ins>gb<ins> ag </ins></code> <code>babg<ins>bag</ins>**</code>

    Constraints:

    • 1 &lt;= s.length, t.length &lt;= 1000

    • s and t consist of English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer numDistinct(String s, String t)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait