Similar idea but without global counter.

class Solution(object): def countSubstrings(self, s): """ :type s: str :rtype: int """ N = len(s) cnt = 0 for i in range(2 * N - 1): pivot = float(i) / 2 left = int(floor(pivot)) right = int(ceil(pivot)) while left >= 0 and right < N and s[left] == s[right]: cnt += 1 left -= 1 right += 1 return cntPalindromic Substrings