算法-目录
题目来源: 剑指 Offer II 020. 回文子字符串的个数
class Solution(object):
def countSubstrings(self, s):
"""
:type s: str
:rtype: int
"""
n=len(s)
ans=0
for i in range(2*n-1):
l,r=i/2,i/2+i%2
while l>=0 and r<n and s[l]==s[r]:
l-=1
r+=1
ans+=1
return ans