<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p>

<p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</code>.</p>

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

<pre>
<strong>Input:</strong> s = &quot;aab&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> The palindrome partitioning [&quot;aa&quot;,&quot;b&quot;] could be produced using 1 cut.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;a&quot;
<strong>Output:</strong> 0
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;ab&quot;
<strong>Output:</strong> 1
</pre>

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

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

class Solution:
    def minCut(self, s: str) -> int:
        # cuts = len(s)

        memoCuts = [[None] * len(s) for _ in range(len(s))]
        memoPalindrome = [[None] * len(s) for _ in range(len(s))]

        def isPal(i, j):
            if i >= j:
                return True
            if memoPalindrome[i][j] != None:
                return memoPalindrome[i][j]
            memoPalindrome[i][j] = (s[i] == s[j] and isPal(i + 1, j - 1))
            return memoPalindrome[i][j]

        def searchMin(i, j, minCut):
            if i == j or isPal(i, j):
                return 0
            if memoCuts[i][j] != None:
                return memoCuts[i][j]

            for k in range(i, j + 1):
                if isPal(i, k):
                    minCut = min(minCut, 1 + searchMin(k + 1, j, minCut))
            memoCuts[i][j] = minCut
            return memoCuts[i][j]
        
        return searchMin(0, len(s) - 1, len(s) - 1)


        # dp = [0] * (len(s) + 1)
        # dp[len(s)] = 0
        # dp[len(s) - 1] = 0
        # dp[len(s) - 2] = 0

        # for i in range(len(s) - 3, -1, -1):
        #     if s[i] == s[i + 2] and s[i] == s[i+1]:
        #         dp[i] = dp[i - 1]
        #     else:
        #         dp[i] = 1 + dp[i - 1]
        # print(dp)

        
        # return dp[0]




        
135715