Python solution

  • 4
    class Solution(object):
        def countSubstrings(self, s):
            :type s: str
            :rtype: int
            res = 0
            for i in range(len(s)):
                for j in range(i, len(s)):
                    if s[i:j+1] == s[i:j+1][::-1]:
                        res += 1
            return res

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.