Return all possible palindrome partitioning of s.
Example: Input: "aab" Output: [ ["aa","b"], ["a","a","b"] ]
code
class Solution { public: vector<vector<string>> partition(string s) { if(s.empty()) return {}; vector<vector<string>> res; vector<string> tmp; partitionCore(s,0,tmp,res); return res; } private: void partitionCore(const string &s,int start,vector<string> &tmp,vector<vector<string>> &res) { if(start==s.size()) { res.emplace_back(tmp); return ; } for(int i=start;i<s.size();++i) { if(!isPalindrome(s,start,i)) continue; tmp.emplace_back(s.substr(start,i-start+1)); partitionCore(s,i+1,tmp,res); tmp.pop_back(); } } bool isPalindrome(const string &s,int start,int end) { while(start<end) if(s.at(start++)!=s.at(end--)) return false; return true; } };