647. Palindromic Substrings

Information

  • Diffculty: Medium

  • Created: 2019-09-02 00:21:12

  • Last Motified: 2019-09-02 00:21:12

Solution

class Solution:
    def countSubstrings(self, s: str) -> int:
        ans = 0
        s = '.' + '.'.join(s) + '.'
        for i in range(len(s)):
            l = 1
            while i - l >= 0 and i + l < len(s) and s[i - l] == s[i + l]:
                l += 1
            ans += l // 2
        return ans