class Solution:
def countSubstrings(self, s: str) -> int:
n = len(s)
ans = 0
for i in range(2*n-1):
left = i//2
right = left + i%2
while left >= 0 and right < n and s[left] == s[right]:
left -= 1
right += 1
ans += 1
return ans
字符串 中等
遍历所有回文中心,在中心扩散回文串
https://leetcode-cn.com/problems/palindromic-substrings/