Update 0647.回文子串.md about rust

This commit is contained in:
fwqaaq
2023-07-24 23:57:57 +08:00
committed by GitHub
parent 00253b560f
commit 69ad28ca0e

View File

@ -517,8 +517,33 @@ function expandRange(s: string, left: number, right: number): number {
}
```
Rust
> 双指针
```rust
impl Solution {
pub fn count_substrings(s: String) -> i32 {
let mut res = 0;
for i in 0..s.len() {
res += Self::extend(&s, i, i, s.len());
res += Self::extend(&s, i, i + 1, s.len());
}
res
}
fn extend(s: &str, mut i: usize, mut j: usize, len: usize) -> i32 {
let mut res = 0;
while i < len && j < len && s[i..=i] == s[j..=j] {
res += 1;
i = i.wrapping_sub(1);
j += 1;
}
res
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">