classSolution:defcountSubstring(self, s:str)->int:
res =0for i inrange(len(s)):
res += self.expand(s, i, i)
res += self.expand(s, i, i +1)return res
defexpand(self, s:str, i:int, j:int):
res =0while i >=0and j <len(s)and s[i]== s[j]:
i -=1
j +=1
res +=1return res