Skip to content

Commit 62efb6c

Browse files
aQuaaQua
aQua
authored and
aQua
committed
115 ut pass
1 parent afb65e1 commit 62efb6c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

Algorithms/0115.distinct-subsequences/distinct-subsequences.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ package Problem0115
22

33
func numDistinct(s string, t string) int {
44
m, n := len(s), len(t)
5-
if m < n {
6-
return 0
7-
}
8-
9-
if n == 0 {
10-
return 1
11-
}
125

136
dp := make([][]int, m+1)
147
for i := 0; i <= m; i++ {
@@ -17,11 +10,7 @@ func numDistinct(s string, t string) int {
1710
}
1811

1912
for j := 1; j <= n; j++ {
20-
if s[:j] == t[:j] {
21-
dp[j][j] = 1
22-
}
23-
24-
for i := j + 1; i <= m; i++ {
13+
for i := j; i <= m; i++ {
2514
if n-j <= m-i && s[i-1] == t[j-1] {
2615
dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
2716
} else {
@@ -30,5 +19,6 @@ func numDistinct(s string, t string) int {
3019

3120
}
3221
}
22+
3323
return dp[m][n]
3424
}

Algorithms/0115.distinct-subsequences/distinct-subsequences_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ func Test_Problem0115(t *testing.T) {
1717
ans int
1818
}{
1919

20+
{
21+
"aaaaaa",
22+
"",
23+
1,
24+
},
25+
2026
{
2127
"aaaaaa",
2228
"aa",

0 commit comments

Comments
 (0)