123456789101112131415161718192021222324 |
- func countSubstrings(s string) int {
- n, cnt := len(s), 0
- if n == 0 {
- return cnt
- }
- for i := range s {
- cnt++
- for j := 1; 0 <= i-j && i+j < n; j++ {
- if s[i-j] == s[i+j] {
- cnt++
- } else {
- break
- }
- }
- for j := 1; 0 <= i-j+1 && i+j < n; j++ {
- if s[i-j+1] == s[i+j] {
- cnt++
- } else {
- break
- }
- }
- }
- return cnt
- }
|