Skip to content

Commit da4c814

Browse files
aQuaaQua
aQua
authored and
aQua
committed
115 added
1 parent 3757065 commit da4c814

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# [115. Distinct Subsequences](https://leetcode.com/problems/distinct-subsequences/)
2+
3+
## 题目
4+
Given a string S and a string T, count the number of distinct subsequences of S which equals T.
5+
6+
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).
7+
8+
Here is an example:
9+
```
10+
S = "rabbbit", T = "rabbit"
11+
Return 3.
12+
```
13+
14+
## 解题思路
15+
16+
见程序注释
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Problem0115
2+
3+
func numDistinct(s string, t string) int {
4+
return 3
5+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package Problem0115
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func Test_Problem0115(t *testing.T) {
11+
ast := assert.New(t)
12+
13+
// tcs is testcase slice
14+
tcs := []struct {
15+
s string
16+
t string
17+
ans int
18+
}{
19+
20+
{
21+
"rabbbit",
22+
"rabbit",
23+
3,
24+
},
25+
26+
// 可以多个 testcase
27+
}
28+
29+
for _, tc := range tcs {
30+
fmt.Printf("~~%v~~\n", tc)
31+
32+
ast.Equal(tc.ans, numDistinct(tc.s, tc.t), "输入:%v", tc)
33+
}
34+
}

0 commit comments

Comments
 (0)