<p>Given a string <code>s</code>, return <em>the number of <strong>palindromic substrings</strong> in it</em>.</p>

<p>A string is a <strong>palindrome</strong> when it reads the same backward as forward.</p>

<p>A <strong>substring</strong> is a contiguous sequence of characters within the string.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abc&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> Three palindromic strings: &quot;a&quot;, &quot;b&quot;, &quot;c&quot;.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aaa&quot;
<strong>Output:</strong> 6
<strong>Explanation:</strong> Six palindromic strings: &quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;aa&quot;, &quot;aa&quot;, &quot;aaa&quot;.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution:
    def countSubstrings(self, s: str) -> int:
        """
            count = 0
            for left, right in range(n):
                count += is_pallendrome(s[left:right])

            recursively check the centre return false if it's not palendromic 

        """

        def is_pallendrome(s, memo = dict()):
            if len(s) == 1:
                return True
            elif len(s) == 2 and s[0] == s[-1]:
                return True
            elif s[0] != s[-1]:
                return False
            else:
                if s[1:-1] not in memo.keys():
                    memo[s[1:-1]] = is_pallendrome(s[1:-1], memo)
                return memo[s[1:-1]]

        count = 0
        for right in range(len(s)+1):
            for left in range(right):
                count += is_pallendrome(s[left:right])
                #print(f"len(s) = {len(s)}, s[{left}][{right}]: {s[left:right]} count = {count}")

        return count
71559