Update 0392.判断子序列.md

This commit is contained in:
fwqaaq
2023-07-23 17:53:05 +08:00
committed by GitHub
parent eb9c4e647b
commit 503c83db8e

View File

@ -278,6 +278,30 @@ impl Solution {
}
```
> 滚动数组
```rust
impl Solution {
pub fn is_subsequence(s: String, t: String) -> bool {
let mut dp = vec![0; t.len() + 1];
let (s, t) = (s.as_bytes(), t.as_bytes());
for &byte_s in s {
let mut pre = 0;
for j in 0..t.len() {
let temp = dp[j + 1];
if byte_s == t[j] {
dp[j + 1] = pre + 1;
} else {
dp[j + 1] = dp[j];
}
pre = temp;
}
}
dp[t.len()] == s.len()
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>