From 6011184b37f9e1d661edef1b124b5e195ef55bd9 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: Tue, 25 Jul 2023 00:18:19 +0800 Subject: [PATCH] =?UTF-8?q?Update=200647.=E5=9B=9E=E6=96=87=E5=AD=90?= =?UTF-8?q?=E4=B8=B2.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0647.回文子串.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 + } +} +``` > 双指针