Skip to content

Commit bf068cc

Browse files
authored
Update 0392.判断子序列.md
添加 Golang 动态规划版本
1 parent 4d7cd29 commit bf068cc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

problems/0392.判断子序列.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,25 @@ const isSubsequence = (s, t) => {
203203
};
204204
```
205205

206+
Go:
207+
```go
208+
func isSubsequence(s string, t string) bool {
209+
dp := make([][]int,len(s)+1)
210+
for i:=0;i<len(dp);i++{
211+
dp[i] = make([]int,len(t)+1)
212+
}
213+
for i:=1;i<len(dp);i++{
214+
for j:=1;j<len(dp[i]);j++{
215+
if s[i-1] == t[j-1]{
216+
dp[i][j] = dp[i-1][j-1] +1
217+
}else{
218+
dp[i][j] = dp[i][j-1]
219+
}
220+
}
221+
}
222+
return dp[len(s)][len(t)]==len(s)
223+
}
224+
```
206225

207226

208227

0 commit comments

Comments
 (0)