class Solution {
public:
vector<vector<string> >ans;
bool isPal(string s,int sta,int end)
{
if(s.length()==0||s.length()==1||sta==end)
return true;
while(sta<end)
{
if(s[sta]==s[end])
{
sta++;
end--;
}
else
return false;
}
return true;
}
void dfs(string s,int sta,vector<string> tmp)
{
if(sta==s.length())
{
ans.push_back(tmp);
return;
}
for(int i=sta;i<=s.length()-1;i++)
{
if(isPal(s,sta,i))
{
tmp.push_back(s.substr(sta,i-sta+1));//do
dfs(s,i+1,tmp);
tmp.pop_back();//undo
}
}
}
vector<vector<string>> partition(string s) {
// Note: The Solution object is instantiated only once and is reused by each test case.
ans.clear();
vector<string> tmp;
dfs(s,0,tmp);
return ans;
}
};