mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
修改 0392.判断子序列.md Go二维DP格式,并增加Go一维DP解法
修改 0392.判断子序列.md Go二维DP格式,并增加Go一维DP解法
This commit is contained in:
@ -240,6 +240,8 @@ function isSubsequence(s: string, t: string): boolean {
|
||||
|
||||
### Go:
|
||||
|
||||
二维DP:
|
||||
|
||||
```go
|
||||
func isSubsequence(s string, t string) bool {
|
||||
dp := make([][]int, len(s) + 1)
|
||||
@ -259,7 +261,24 @@ func isSubsequence(s string, t string) bool {
|
||||
}
|
||||
```
|
||||
|
||||
Rust:
|
||||
一维DP:
|
||||
|
||||
```go
|
||||
func isSubsequence(s string, t string) bool {
|
||||
dp := make([]int, len(s) + 1)
|
||||
for i := 1; i <= len(t); i ++ {
|
||||
for j := len(s); j >= 1; j -- {
|
||||
if t[i - 1] == s[j - 1] {
|
||||
dp[j] = dp[j - 1] + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[len(s)] == len(s)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Rust:
|
||||
|
||||
```rust
|
||||
impl Solution {
|
||||
|
Reference in New Issue
Block a user