mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #690 from Spongecaptain/patch-6
Update 0392.判断子序列.md
This commit is contained in:
@ -203,6 +203,25 @@ const isSubsequence = (s, t) => {
|
||||
};
|
||||
```
|
||||
|
||||
Go:
|
||||
```go
|
||||
func isSubsequence(s string, t string) bool {
|
||||
dp := make([][]int,len(s)+1)
|
||||
for i:=0;i<len(dp);i++{
|
||||
dp[i] = make([]int,len(t)+1)
|
||||
}
|
||||
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] +1
|
||||
}else{
|
||||
dp[i][j] = dp[i][j-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[len(s)][len(t)]==len(s)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user