File tree Expand file tree Collapse file tree 1 file changed +45
-15
lines changed
algorithms/cpp/distinctSubsequences Expand file tree Collapse file tree 1 file changed +45
-15
lines changed Original file line number Diff line number Diff line change 2
2
// Author : Hao Chen
3
3
// Date : 2014-07-06
4
4
5
- /* *********************************************************************************
6
- *
7
- * Given a string S and a string T, count the number of distinct subsequences of T in S.
8
- *
9
- * A subsequence of a string is a new string which is formed from the original string
10
- * by deleting some (can be none) of the characters without disturbing the relative positions
11
- * of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).
12
- *
13
- * Here is an example:
14
- * S = "rabbbit", T = "rabbit"
15
- *
16
- * Return 3.
17
- *
18
- *
19
- **********************************************************************************/
5
+ /* ****************************************************************************************************
6
+ *
7
+ * Given a string S and a string T, count the number of distinct subsequences of S which equals T.
8
+ *
9
+ * A subsequence of a string is a new string which is formed from the original string by deleting some
10
+ * (can be none) of the characters without disturbing the relative positions of the remaining
11
+ * characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).
12
+ *
13
+ * Example 1:
14
+ *
15
+ * Input: S = "rabbbit", T = "rabbit"
16
+ * Output: 3
17
+ * Explanation:
18
+ *
19
+ * As shown below, there are 3 ways you can generate "rabbit" from S.
20
+ * (The caret symbol ^ means the chosen letters)
21
+ *
22
+ * rabbbit
23
+ * ^^^^ ^^
24
+ * rabbbit
25
+ * ^^ ^^^^
26
+ * rabbbit
27
+ * ^^^ ^^^
28
+ *
29
+ * Example 2:
30
+ *
31
+ * Input: S = "babgbag", T = "bag"
32
+ * Output: 5
33
+ * Explanation:
34
+ *
35
+ * As shown below, there are 5 ways you can generate "bag" from S.
36
+ * (The caret symbol ^ means the chosen letters)
37
+ *
38
+ * babgbag
39
+ * ^^ ^
40
+ * babgbag
41
+ * ^^ ^
42
+ * babgbag
43
+ * ^ ^^
44
+ * babgbag
45
+ * ^ ^^
46
+ * babgbag
47
+ * ^^^
48
+ *
49
+ ******************************************************************************************************/
20
50
#include < stdlib.h>
21
51
#include < time.h>
22
52
#include < string.h>
You can’t perform that action at this time.
0 commit comments