Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69ad28c

Browse files
authored
Update 0647.回文子串.md about rust
1 parent 00253b5 commit 69ad28c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎problems/0647.回文子串.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,33 @@ function expandRange(s: string, left: number, right: number): number {
517517
}
518518
```
519519

520+
Rust:
520521

521522

523+
> 双指针
524+
525+
```rust
526+
impl Solution {
527+
pub fn count_substrings(s: String) -> i32 {
528+
let mut res = 0;
529+
for i in 0..s.len() {
530+
res += Self::extend(&s, i, i, s.len());
531+
res += Self::extend(&s, i, i + 1, s.len());
532+
}
533+
res
534+
}
535+
536+
fn extend(s: &str, mut i: usize, mut j: usize, len: usize) -> i32 {
537+
let mut res = 0;
538+
while i < len && j < len && s[i..=i] == s[j..=j] {
539+
res += 1;
540+
i = i.wrapping_sub(1);
541+
j += 1;
542+
}
543+
res
544+
}
545+
}
546+
```
522547

523548
<p align="center">
524549
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /