MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / count_substrings

Function count_substrings

647-palindromic-substrings.rs:1–17  ·  view source on GitHub ↗
(s: String)

Source from the content-addressed store, hash-verified

1pub fn count_substrings(s: String) -> i32 {
2 pub fn is_palindromic(cs: &[char]) -> bool {
3 // println!("{:?}", cs.clone().to_vec());
4 let tmp = cs.clone().to_vec();
5 let mut tmp_rev = cs.clone().to_vec();
6 tmp_rev.reverse();
7 tmp == tmp_rev
8 }
9 let cs = s.chars().collect::<Vec<char>>();
10 let mut ret = 0;
11 for i in 1 ..= s.len() {
12 for j in 0 ..= (s.len() - i) {
13 if is_palindromic(&cs[j..j+i]) { ret += 1 }
14 }
15 }
16 ret
17}
18
19fn main() {
20 println!("{:?}", count_substrings("abc".to_string()));

Callers

nothing calls this directly

Calls 1

is_palindromicFunction · 0.85

Tested by

no test coverage detected