classSolution: defcountSubstrings(self, s: str) -> int: n, ans = len(s), 0 for i inrange(n): ans += self.check(i, i, s) ans += self.check(i, i+1, s) return ans defcheck(self, left, right, s): ans = 0 while left >= 0and right <= len(s)-1and s[left] == s[right]: ans += 1 left -= 1 right += 1 return ans