Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s = "aab"
,
Return
[ ["aa","b"], ["a","a","b"] ]
class Solution { private: vector<vector<string> > res; public: void DFS(string s, vector<string> &ans) { if(s.size()<1) { res.push_back(ans); return; } for(int i=0;i<s.size();i++) { int start=0; int end=i; while(start<end) { if(s[start]==s[end]) { start++; end--; } else break; } if(start>=end) { ans.push_back(s.substr(0,i+1)); DFS(s.substr(i+1),ans); ans.pop_back(); } } } vector<vector<string>> partition(string s) { res.clear(); vector<string> ans; DFS(s,ans); return res; } };