<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 {
public:
    vector<vector<string>> finalans;
    vector<vector<string>> finalans2;

    bool mypalin(string s){
        int i,n=s.size();

        for(i=0;i<n;i++)
            if(s[i]!=s[n-i-1])
                return false;

        return true;
    }


    vector<vector<string>> partition(string s) {
        int i,j,n2,n=s.length();
        
        string s1=s.substr(0,1);
        vector<string> v1;
        v1.push_back(s1);
        finalans.push_back(v1);

        for(i=1;i<n;i++){
            s1=s.substr(i,1);
            n2=finalans.size();

            for(int j=0;j<n2;j++){
                
                //not cutting
                if(true){
                    v1=finalans[j];
                    v1.back().push_back(s[i]);
                    finalans.push_back(v1);
                }
                            
                // cutting at this index
                finalans[j].push_back(s1);
            }
        }
        
        for(i=0;i<finalans.size();i++){
            bool mybool=true;
            for(j=0;j<finalans[i].size();j++)
                if(!mypalin(finalans[i][j]))
                    mybool=false;

            if(mybool)
                finalans2.push_back(finalans[i]);
        }

        return finalans2;
    }
};
126576