classSolution: defcountSubstrings(self, s: str) -> int: sLen, result = len(s), 0 for i in range(2*sLen-1): left, right = i//2, i//2 + i%2 while left >=0and right < sLen and s[left] == s[right]: result += 1 left -= 1 right += 1 return result
classSolution { public: intcountSubstrings(string s){ if (s.empty()) { return0; } int n = s.size(), result = 0; for (int i = 0; i < n; i++) { getMoreResult(s, i, i, result); getMoreResult(s, i, i+1, result); } return result; } voidgetMoreResult(string s, int i, int j, int& result){ while (i >= 0 && j < s.size() && s[i] == s[j]) { i--; j++; result++; } } };