|
| 1 | +<h2><a href="https://leetcode.com/problems/distinct-subsequences/">115. Distinct Subsequences</a></h2><h3>Hard</h3><hr><div><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> |
| 2 | + |
| 3 | +<p>A string'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' relative positions. (i.e., <code>"ACE"</code> is a subsequence of <code>"ABCDE"</code> while <code>"AEC"</code> is not).</p> |
| 4 | + |
| 5 | +<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong>Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre><strong>Input:</strong> s = "rabbbit", t = "rabbit" |
| 11 | +<strong>Output:</strong> 3 |
| 12 | +<strong>Explanation:</strong> |
| 13 | +As shown below, there are 3 ways you can generate "rabbit" from S. |
| 14 | +<code><strong><u>rabb</u></strong>b<strong><u>it</u></strong></code> |
| 15 | +<code><strong><u>ra</u></strong>b<strong><u>bbit</u></strong></code> |
| 16 | +<code><strong><u>rab</u></strong>b<strong><u>bit</u></strong></code> |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong>Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre><strong>Input:</strong> s = "babgbag", t = "bag" |
| 22 | +<strong>Output:</strong> 5 |
| 23 | +<strong>Explanation:</strong> |
| 24 | +As shown below, there are 5 ways you can generate "bag" from S. |
| 25 | +<code><strong><u>ba</u></strong>b<u><strong>g</strong></u>bag</code> |
| 26 | +<code><strong><u>ba</u></strong>bgba<strong><u>g</u></strong></code> |
| 27 | +<code><u><strong>b</strong></u>abgb<strong><u>ag</u></strong></code> |
| 28 | +<code>ba<u><strong>b</strong></u>gb<u><strong>ag</strong></u></code> |
| 29 | +<code>babg<strong><u>bag</u></strong></code></pre> |
| 30 | + |
| 31 | +<p> </p> |
| 32 | +<p><strong>Constraints:</strong></p> |
| 33 | + |
| 34 | +<ul> |
| 35 | + <li><code>1 <= s.length, t.length <= 1000</code></li> |
| 36 | + <li><code>s</code> and <code>t</code> consist of English letters.</li> |
| 37 | +</ul> |
| 38 | +</div> |
0 commit comments