mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Update 0115.不同的子序列.md
添加 Go 语言版本
This commit is contained in:
@ -221,6 +221,30 @@ class SolutionDP2:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```go
|
||||||
|
func numDistinct(s string, t string) int {
|
||||||
|
dp:= make([][]int,len(s)+1)
|
||||||
|
for i:=0;i<len(dp);i++{
|
||||||
|
dp[i] = make([]int,len(t)+1)
|
||||||
|
}
|
||||||
|
// 初始化
|
||||||
|
for i:=0;i<len(dp);i++{
|
||||||
|
dp[i][0] = 1
|
||||||
|
}
|
||||||
|
// dp[0][j] 为 0,默认值,因此不需要初始化
|
||||||
|
for i:=1;i<len(dp);i++{
|
||||||
|
for j:=1;j<len(dp[i]);j++{
|
||||||
|
if s[i-1] == t[j-1]{
|
||||||
|
dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
|
||||||
|
}else{
|
||||||
|
dp[i][j] = dp[i-1][j]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[len(dp)-1][len(dp[0])-1]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Javascript:
|
Javascript:
|
||||||
```javascript
|
```javascript
|
||||||
|
Reference in New Issue
Block a user