<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"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "aab"
<strong>Output:</strong> [["a","a","b"],["aa","b"]]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "a"
<strong>Output:</strong> [["a"]]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 16</code></li>
	<li><code>s</code> contains only lowercase English letters.</li>
</ul>

class Solution:
    def partition(self, s: str) -> List[List[str]]:
        result = []
        
        n = len(s)
        dp = [[False] * n for _ in range(n)]
        for l in range(1,n+1):
            for i in range(n-l+1):
                j = i+l-1
                dp[i][j] = (i == j) or (s[i] == s[j] and (j == i+1 or dp[i+1][j-1]))

        self.get_partitions(s, 0, [], dp, result)
        return result
        
    def get_partitions(self, s, i, partitions, dp, result):
        if i == len(s):
            result.append([''.join(p) for p in partitions])
            return
        partitions.append([])
        for j in range(i, len(s)):
            partitions[-1].append(s[j])
            if dp[i][j]:
                self.get_partitions(s,j+1,partitions, dp, result)

        
        partitions.pop()

38183