LC 0647 [M] Palindromic Substrings - ALawliet/algorithms GitHub Wiki

same idea as: https://github.com/codewithsenpai/algos/wiki/LC-0005-%5BM%5D-Longest-Palindromic-Substring

class Solution:
    def countSubstrings(self, s: str) -> int:
        self.count = 0
        
        def expand(l, r):
            while l >= 0 and r < len(s) and s[l] == s[r]:
                l -=1 ; r += 1
                self.count += 1

        for i in range(len(s)):
            odd = expand(i, i)
            even = expand(i, i+1)
        
        return self.count