Merge branch 'master' of github.com:jinbudaily/leetcode-master

This commit is contained in:
jinbudaily
2023-08-23 15:14:34 +08:00
38 changed files with 963 additions and 133 deletions

View File

@@ -276,7 +276,26 @@ function longestPalindromeSubseq(s: string): number {
};
```
Rust:
```rust
impl Solution {
pub fn longest_palindrome_subseq(s: String) -> i32 {
let mut dp = vec![vec![0; s.len()]; s.len()];
for i in (0..s.len()).rev() {
dp[i][i] = 1;
for j in i + 1..s.len() {
if s[i..=i] == s[j..=j] {
dp[i][j] = dp[i + 1][j - 1] + 2;
continue;
}
dp[i][j] = dp[i + 1][j].max(dp[i][j - 1]);
}
}
dp[0][s.len() - 1]
}
}
```
<p align="center">