diff --git a/problems/0647.回文子串.md b/problems/0647.回文子串.md index 35396192..52f12d9b 100644 --- a/problems/0647.回文子串.md +++ b/problems/0647.回文子串.md @@ -519,6 +519,24 @@ function expandRange(s: string, left: number, right: number): number { Rust: +```rust +impl Solution { + pub fn count_substrings(s: String) -> i32 { + let mut dp = vec![vec![false; s.len()]; s.len()]; + let mut res = 0; + + for i in (0..s.len()).rev() { + for j in i..s.len() { + if s[i..=i] == s[j..=j] && (j - i <= 1 || dp[i + 1][j - 1]) { + dp[i][j] = true; + res += 1; + } + } + } + res + } +} +``` > 双指针